Add AGENTS.md and deploy configs to the API repo.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -0,0 +1,115 @@
|
||||
# Deploy — SuperAdmin on shared montime host
|
||||
|
||||
Host: `185.50.38.53` (SSH port `3031`)
|
||||
Domain: `https://adm.montzar.ir`
|
||||
DB: Postgres `superadmin` (owner `montime`) — already created
|
||||
API port: `3010` (3000=montime, 3001=forisanad)
|
||||
|
||||
## Layout on server
|
||||
|
||||
```text
|
||||
/var/www/superadmin/
|
||||
api/ # clone of controlPanel/api.git
|
||||
deploy/ # nginx + pm2 + this guide (in api repo)
|
||||
web/ # clone of controlPanel/web.git (Vue dist)
|
||||
```
|
||||
|
||||
## 1) Clone / pull
|
||||
|
||||
```bash
|
||||
sudo mkdir -p /var/www/superadmin
|
||||
sudo chown montime:montime /var/www/superadmin
|
||||
|
||||
cd /var/www/superadmin
|
||||
git clone https://get.feep.ir/controlPanel/api.git api
|
||||
git clone https://get.feep.ir/controlPanel/web.git web
|
||||
```
|
||||
|
||||
Later updates: `git pull` in each folder.
|
||||
|
||||
## 2) API `.env`
|
||||
|
||||
```bash
|
||||
cd /var/www/superadmin/api
|
||||
cp .env.example .env
|
||||
nano .env
|
||||
```
|
||||
|
||||
Required:
|
||||
|
||||
```env
|
||||
NODE_ENV=production
|
||||
PORT=3010
|
||||
DATABASE_URL="postgresql://montime:YOUR_PASSWORD@127.0.0.1:5432/superadmin?schema=public"
|
||||
JWT_SECRET="long-random-production-secret"
|
||||
JWT_EXPIRES_IN="7d"
|
||||
CORS_ORIGIN="https://adm.montzar.ir"
|
||||
PUBLIC_API_URL="https://adm.montzar.ir"
|
||||
SEED_ADMIN_MOBILE="09128081392"
|
||||
SEED_ADMIN_PASSWORD="change-me"
|
||||
# CENTRAL_SMS_* as needed
|
||||
```
|
||||
|
||||
Password = same Postgres password that works for `psql -h 127.0.0.1 -U montime -d superadmin`.
|
||||
|
||||
## 3) Install, migrate, build, seed
|
||||
|
||||
```bash
|
||||
cd /var/www/superadmin/api
|
||||
npm ci
|
||||
npx prisma generate
|
||||
npx prisma migrate deploy
|
||||
npm run build
|
||||
npm run prisma:seed
|
||||
# optional first import:
|
||||
# npm run prisma:import-users
|
||||
```
|
||||
|
||||
## 4) PM2
|
||||
|
||||
```bash
|
||||
pm2 start /var/www/superadmin/api/deploy/ecosystem.config.cjs
|
||||
pm2 save
|
||||
pm2 status
|
||||
curl -s http://127.0.0.1:3010/api/health || true
|
||||
```
|
||||
|
||||
## 5) Web build
|
||||
|
||||
Same-origin: leave `VITE_API_BASE` unset (defaults to `/api`).
|
||||
|
||||
```bash
|
||||
cd /var/www/superadmin/web
|
||||
npm ci
|
||||
npm run build
|
||||
# dist → /var/www/superadmin/web/dist
|
||||
```
|
||||
|
||||
## 6) Nginx
|
||||
|
||||
```bash
|
||||
sudo cp /var/www/superadmin/api/deploy/nginx-adm.montzar.ir.conf /etc/nginx/sites-available/adm.montzar.ir
|
||||
sudo ln -sf /etc/nginx/sites-available/adm.montzar.ir /etc/nginx/sites-enabled/
|
||||
sudo nginx -t && sudo systemctl reload nginx
|
||||
```
|
||||
|
||||
SSL: if Certbot already issued for `adm.montzar.ir`, paths in the conf should match. Otherwise:
|
||||
|
||||
```bash
|
||||
sudo certbot --nginx -d adm.montzar.ir
|
||||
```
|
||||
|
||||
## 7) Smoke
|
||||
|
||||
1. Open `https://adm.montzar.ir` → login
|
||||
2. `https://adm.montzar.ir/get_user?domain=montpar.ir` (or any known domain)
|
||||
3. Confirm uploads/logo URLs use `PUBLIC_API_URL`
|
||||
|
||||
## Local development note
|
||||
|
||||
Prisma provider is **PostgreSQL** only. Local options:
|
||||
|
||||
- Docker: `docker run -d -p 5432:5432 -e POSTGRES_PASSWORD=postgres -e POSTGRES_DB=superadmin postgres:16`
|
||||
- Or point `DATABASE_URL` at the server DB only for short tests (prefer local DB)
|
||||
|
||||
SQLite history is kept under `prisma/migrations_sqlite_archive/` (reference only; not applied by `migrate deploy`).
|
||||
@@ -0,0 +1,24 @@
|
||||
/**
|
||||
* PM2 — SuperAdmin API on shared montime host.
|
||||
* Port 3010 avoids clash with montime-api (:3000) and forisanad (:3001).
|
||||
*
|
||||
* Usage (on server, as montime):
|
||||
* pm2 start /var/www/superadmin/api/deploy/ecosystem.config.cjs
|
||||
*/
|
||||
module.exports = {
|
||||
apps: [
|
||||
{
|
||||
name: 'superadmin-api',
|
||||
cwd: '/var/www/superadmin/api',
|
||||
script: 'dist/main.js',
|
||||
instances: 1,
|
||||
exec_mode: 'fork',
|
||||
env: {
|
||||
NODE_ENV: 'production',
|
||||
PORT: '3010',
|
||||
},
|
||||
max_memory_restart: '400M',
|
||||
time: true,
|
||||
},
|
||||
],
|
||||
};
|
||||
@@ -0,0 +1,73 @@
|
||||
# Place under /etc/nginx/sites-available/adm.montzar.ir
|
||||
# SSL: assume Certbot already issued for adm.montzar.ir (or enable after first HTTP).
|
||||
#
|
||||
# Single domain: SPA at / + Nest API under /api + public get_user/get_version + uploads.
|
||||
|
||||
upstream superadmin_api {
|
||||
server 127.0.0.1:3010;
|
||||
keepalive 8;
|
||||
}
|
||||
|
||||
server {
|
||||
listen 80;
|
||||
listen [::]:80;
|
||||
server_name adm.montzar.ir;
|
||||
return 301 https://$host$request_uri;
|
||||
}
|
||||
|
||||
server {
|
||||
listen 443 ssl http2;
|
||||
listen [::]:443 ssl http2;
|
||||
server_name adm.montzar.ir;
|
||||
|
||||
# Certbot paths — adjust if different on this host
|
||||
ssl_certificate /etc/letsencrypt/live/adm.montzar.ir/fullchain.pem;
|
||||
ssl_certificate_key /etc/letsencrypt/live/adm.montzar.ir/privkey.pem;
|
||||
include /etc/letsencrypt/options-ssl-nginx.conf;
|
||||
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;
|
||||
|
||||
root /var/www/superadmin/web/dist;
|
||||
index index.html;
|
||||
|
||||
client_max_body_size 20M;
|
||||
|
||||
location /api/ {
|
||||
proxy_pass http://superadmin_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 = /get_user {
|
||||
proxy_pass http://superadmin_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 = /get_version {
|
||||
proxy_pass http://superadmin_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://superadmin_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 / {
|
||||
try_files $uri $uri/ /index.html;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user