Initial commit: API and deploy configs

This commit is contained in:
Noro Studio
2026-06-30 00:51:32 +03:30
commit b0361594b1
15 changed files with 985 additions and 0 deletions
+1
View File
@@ -0,0 +1 @@
*.log
+29
View File
@@ -0,0 +1,29 @@
#!/usr/bin/env bash
set -euo pipefail
APP_ROOT="${APP_ROOT:-/var/www/studionoro}"
echo "==> Pull latest code (if using git)..."
cd "$APP_ROOT"
git pull || true
echo "==> Rebuild API..."
cd "$APP_ROOT/api"
npm ci --omit=dev || npm install --omit=dev
echo "==> Rebuild Nuxt..."
cd "$APP_ROOT/nuxt-tailwind-app"
npm ci || npm install
npm run build
echo "==> Rebuild admin..."
cd "$APP_ROOT/admin"
npm ci || npm install
npm run build
echo "==> Restart services..."
cd "$APP_ROOT"
pm2 restart ecosystem.config.cjs
systemctl reload nginx
echo "Deploy complete."
+2
View File
@@ -0,0 +1,2 @@
NUXT_PUBLIC_CMS_API_URL=https://api.studionoro.ir
NODE_ENV=production
+84
View File
@@ -0,0 +1,84 @@
# Nginx site config for studionoro.ir
# Copy to: /etc/nginx/sites-available/studionoro
# Enable: sudo ln -sf /etc/nginx/sites-available/studionoro /etc/nginx/sites-enabled/
upstream studionoro_web {
server 127.0.0.1:3000;
keepalive 32;
}
upstream studionoro_api {
server 127.0.0.1:4000;
keepalive 32;
}
# --- Main website (Nuxt) ---
server {
listen 80;
listen [::]:80;
server_name studionoro.ir www.studionoro.ir;
client_max_body_size 20M;
location / {
proxy_pass http://studionoro_web;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_read_timeout 60s;
}
}
# --- Admin panel (Vue static build) ---
server {
listen 80;
listen [::]:80;
server_name admin.studionoro.ir;
root /var/www/studionoro/admin/dist;
index index.html;
client_max_body_size 20M;
location /api/ {
proxy_pass http://studionoro_api;
proxy_http_version 1.1;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
location /uploads/ {
proxy_pass http://studionoro_api;
proxy_http_version 1.1;
proxy_set_header Host $host;
expires 30d;
add_header Cache-Control "public, immutable";
}
location / {
try_files $uri $uri/ /index.html;
}
}
# --- API backend ---
server {
listen 80;
listen [::]:80;
server_name api.studionoro.ir;
client_max_body_size 20M;
location / {
proxy_pass http://studionoro_api;
proxy_http_version 1.1;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}
+31
View File
@@ -0,0 +1,31 @@
module.exports = {
apps: [
{
name: 'studionoro-api',
cwd: '/var/www/studionoro/api',
script: 'src/index.js',
instances: 1,
autorestart: true,
max_memory_restart: '300M',
env: {
NODE_ENV: 'production',
PORT: 4000,
},
},
{
name: 'studionoro-web',
cwd: '/var/www/studionoro/nuxt-tailwind-app',
script: '.output/server/index.mjs',
instances: 1,
autorestart: true,
max_memory_restart: '512M',
env: {
NODE_ENV: 'production',
PORT: 3000,
HOST: '127.0.0.1',
NITRO_HOST: '127.0.0.1',
NITRO_PORT: '3000',
},
},
],
}
+90
View File
@@ -0,0 +1,90 @@
#!/usr/bin/env bash
set -euo pipefail
# Studio Noro — VPS bootstrap (Ubuntu 22.04/24.04)
# Run as root or with sudo on a fresh VPS after uploading the project.
APP_ROOT="${APP_ROOT:-/var/www/studionoro}"
DOMAIN="${DOMAIN:-studionoro.ir}"
ADMIN_DOMAIN="${ADMIN_DOMAIN:-admin.studionoro.ir}"
API_DOMAIN="${API_DOMAIN:-api.studionoro.ir}"
echo "==> Installing system packages..."
export DEBIAN_FRONTEND=noninteractive
apt-get update
apt-get install -y curl git nginx ufw certbot python3-certbot-nginx
echo "==> Installing Node.js 20 LTS..."
if ! command -v node >/dev/null 2>&1; then
curl -fsSL https://deb.nodesource.com/setup_20.x | bash -
apt-get install -y nodejs
fi
echo "==> Installing PM2..."
npm install -g pm2
echo "==> Configuring firewall..."
ufw allow OpenSSH
ufw allow 'Nginx Full'
ufw --force enable
echo "==> Creating app directory..."
mkdir -p "$APP_ROOT"
if [ ! -d "$APP_ROOT/api" ]; then
echo "ERROR: Project files not found in $APP_ROOT"
echo "Upload or clone your project to $APP_ROOT first."
exit 1
fi
echo "==> Installing API dependencies..."
cd "$APP_ROOT/api"
if [ ! -f .env ]; then
cp .env.example .env
echo "WARNING: Edit $APP_ROOT/api/.env before going live (JWT_SECRET, ADMIN_PASSWORD)."
fi
npm ci --omit=dev || npm install --omit=dev
echo "==> Seeding API data (first run)..."
npm run seed || true
echo "==> Building Nuxt frontend..."
cd "$APP_ROOT/nuxt-tailwind-app"
if [ ! -f .env ]; then
cp "$APP_ROOT/deploy/env/nuxt.env.example" .env
fi
npm ci || npm install
npm run build
echo "==> Building admin panel..."
cd "$APP_ROOT/admin"
npm ci || npm install
npm run build
echo "==> Installing Nginx config..."
cp "$APP_ROOT/deploy/nginx/studionoro.conf" /etc/nginx/sites-available/studionoro
ln -sf /etc/nginx/sites-available/studionoro /etc/nginx/sites-enabled/studionoro
rm -f /etc/nginx/sites-enabled/default
nginx -t
systemctl reload nginx
echo "==> Starting PM2 apps..."
cp "$APP_ROOT/deploy/pm2/ecosystem.config.cjs" "$APP_ROOT/ecosystem.config.cjs"
cd "$APP_ROOT"
pm2 start ecosystem.config.cjs
pm2 save
pm2 startup systemd -u root --hp /root || pm2 startup
echo "==> Requesting SSL certificates..."
certbot --nginx \
-d "$DOMAIN" -d "www.$DOMAIN" \
-d "$ADMIN_DOMAIN" \
-d "$API_DOMAIN" \
--non-interactive --agree-tos -m "admin@$DOMAIN" || \
echo "Certbot failed — set DNS first, then run certbot manually."
echo ""
echo "Done. Verify:"
echo " https://$DOMAIN"
echo " https://$ADMIN_DOMAIN"
echo " https://$API_DOMAIN/health"
+14
View File
@@ -0,0 +1,14 @@
# Copy project to VPS (run from Windows PowerShell in C:\Users\SMB\Projects)
# Option A — using SCP (replace VPS_IP and user):
# scp -r api admin nuxt-tailwind-app deploy user@VPS_IP:/var/www/studionoro/
# Option B — using Git on VPS (recommended):
# 1. Push this repo to GitHub/GitLab
# 2. On VPS: git clone YOUR_REPO_URL /var/www/studionoro
# After files are on VPS:
# ssh user@VPS_IP
# cd /var/www/studionoro
# chmod +x deploy/setup-vps.sh deploy/deploy.sh
# sudo bash deploy/setup-vps.sh