# DEPLOY CPANEL - THINKERS BACKEND

Guide de deploiement backend Node.js/Prisma sur cPanel pour la production.

## 1) Variables .env production (obligatoires)

Utiliser `.env.production.example` comme base puis copier en `.env`.

```env
NODE_ENV=production
BASE_URL=https://api.thinkers-production.com
CORS_ORIGINS=https://thinkers-production.com,https://www.thinkers-production.com
COOKIE_DOMAIN=.thinkers-production.com
COOKIE_SECURE=true
UPLOADS_PUBLIC_URL=https://api.thinkers-production.com/uploads
```

Notes:
- `COOKIE_SAME_SITE=lax` est valide ici (front et API sur le meme eTLD+1).
- `PORT` reste `4000` (ou port interne defini par le Node App Manager).
- `DATABASE_URL`, `JWT_ACCESS_SECRET`, `JWT_REFRESH_SECRET` doivent etre renseignes.

## 2) Deploiement backend (ordre exact)

```bash
cd /home/<cpanel_user>/thinkers-backend
npm ci
npm run build
npm run migrate
npm run seed   # premiere installation uniquement
```

## 3) Uploads publics

Verifier:
- dossier `uploads/` present
- dossier writable par le process Node
- route publique active: `https://api.thinkers-production.com/uploads/...`

Commandes utiles:

```bash
mkdir -p uploads/services uploads/gallery uploads/gallery/thumbs uploads/partners uploads/settings uploads/about uploads/hero
chmod -R 755 uploads
```

## 4) Demarrage process

### Option A - cPanel Node.js App
- Application mode: `Production`
- Startup file: `dist/main.js`
- Restart app apres chaque deploy

### Option B - PM2

```bash
pm2 start dist/main.js --name thinkers-api
pm2 save
pm2 restart thinkers-api
```

## 5) Verification immediate

```bash
curl -i https://api.thinkers-production.com/health
```

Attendu:
- HTTP `200`
- JSON contenant `"status":"ok"`

## 6) Mise a jour (release suivante)

```bash
cd /home/<cpanel_user>/thinkers-backend
git pull
npm ci
npm run build
npm run migrate
pm2 restart thinkers-api  # ou restart via cPanel Node app
```

## 7) Checklist backend GO LIVE

- [ ] `.env` production configure avec les valeurs obligatoires
- [ ] `npm ci` OK
- [ ] `npm run build` OK
- [ ] `npm run migrate` OK
- [ ] `npm run seed` execute une seule fois (si premiere install)
- [ ] `uploads/` writable + accessible publiquement
- [ ] process Node redemarre
- [ ] `/health` retourne 200
- [ ] login admin + cookie httpOnly valide depuis le front prod

## 8) Reference globale

Pour la procedure complete front+back+cPanel+smoke tests, voir `../PROD_GO_LIVE.md`.
