# πŸš€ TurboTrades - Simple Deployment Quick deployment guide for TurboTrades on turbotrades.dev. --- ## πŸ“‹ Server Setup (Already Done) - **Frontend:** https://turbotrades.dev β†’ `/var/www/html/turbotrades` - **Backend:** https://api.turbotrades.dev β†’ Node.js on port 3000 - **WebSocket:** https://ws.turbotrades.dev β†’ Node.js on port 3000 - **Backend Code:** `/root/ttbackend` - **Nginx:** Already configured - **SSL:** Already configured --- ## 🎯 Quick Deploy ### SSH to Server and Run Deploy Script ```bash # SSH into server ssh root@turbotrades.dev # Navigate to backend directory cd /root/ttbackend # Pull latest code git pull origin main # Run deploy script ./deploy.sh ``` That's it! βœ… --- ## πŸ”„ What the Deploy Script Does 1. ⏸️ Stops the backend (PM2) 2. πŸ’Ύ Creates a backup 3. πŸ“₯ Pulls latest code from Gitea 4. πŸ“¦ Installs backend dependencies 5. 🎨 Builds frontend 6. πŸš€ Deploys frontend to `/var/www/html/turbotrades` 7. ▢️ Restarts backend with PM2 8. βœ… Runs health checks --- ## πŸ› οΈ Manual Deploy (Without Script) ```bash # SSH to server ssh root@turbotrades.dev # Stop backend pm2 stop turbotrades-backend # Navigate to backend cd /root/ttbackend # Pull latest code git pull origin main # Install backend dependencies npm ci --production # Build frontend cd frontend npm ci npm run build # Deploy frontend rm -rf /var/www/html/turbotrades/* cp -r dist/* /var/www/html/turbotrades/ chown -R www-data:www-data /var/www/html/turbotrades # Back to backend cd /root/ttbackend # Restart backend pm2 restart turbotrades-backend pm2 save # Check status pm2 logs turbotrades-backend ``` --- ## πŸ“Š Monitoring ### Check Backend Status ```bash pm2 list pm2 logs turbotrades-backend pm2 monit ``` ### Check Nginx Logs ```bash tail -f /var/log/nginx/turbotrades-error.log tail -f /var/log/nginx/api-turbotrades-error.log tail -f /var/log/nginx/ws-turbotrades-error.log ``` ### Health Checks ```bash # Backend API curl https://api.turbotrades.dev/api/health # Frontend curl https://turbotrades.dev # WebSocket (requires wscat) wscat -c wss://ws.turbotrades.dev ``` --- ## πŸ› Quick Troubleshooting ### Backend Won't Start ```bash # Check logs pm2 logs turbotrades-backend # Check if port 3000 is free netstat -tulpn | grep 3000 # Check MongoDB systemctl status mongod # Restart everything pm2 restart turbotrades-backend ``` ### Frontend Not Loading ```bash # Check if files exist ls -la /var/www/html/turbotrades/ # Check permissions chown -R www-data:www-data /var/www/html/turbotrades chmod -R 755 /var/www/html/turbotrades # Check nginx nginx -t systemctl reload nginx ``` ### 502 Bad Gateway ```bash # Backend is probably down pm2 restart turbotrades-backend # Check backend is listening netstat -tulpn | grep 3000 # Check nginx logs tail -f /var/log/nginx/api-turbotrades-error.log ``` --- ## πŸ”„ Rollback ```bash # SSH to server ssh root@turbotrades.dev # Stop current version pm2 stop turbotrades-backend # List backups ls -lt /root/ | grep ttbackend-backup # Restore from backup cd /root rm -rf ttbackend cp -r ttbackend-backup-YYYYMMDD-HHMMSS ttbackend # Restart cd ttbackend pm2 restart turbotrades-backend ``` --- ## πŸ“ Update .env If you need to update environment variables: ```bash ssh root@turbotrades.dev cd /root/ttbackend nano .env # After editing, restart pm2 restart turbotrades-backend ``` --- ## 🎯 Deployment Workflow ### For Code Changes ```bash # On your local machine git add . git commit -m "Your changes" git push origin main # On the server ssh root@turbotrades.dev cd /root/ttbackend ./deploy.sh ``` ### For Environment Changes Only ```bash ssh root@turbotrades.dev cd /root/ttbackend nano .env pm2 restart turbotrades-backend ``` ### For Frontend Only ```bash ssh root@turbotrades.dev cd /root/ttbackend git pull origin main cd frontend npm ci npm run build rm -rf /var/www/html/turbotrades/* cp -r dist/* /var/www/html/turbotrades/ chown -R www-data:www-data /var/www/html/turbotrades ``` ### For Backend Only ```bash ssh root@turbotrades.dev cd /root/ttbackend git pull origin main npm ci --production pm2 restart turbotrades-backend ``` --- ## πŸ” Required Environment Variables Make sure these are set in `/root/ttbackend/.env`: ```env NODE_ENV=production PORT=3000 FRONTEND_URL=https://turbotrades.dev BACKEND_URL=https://api.turbotrades.dev WS_URL=https://ws.turbotrades.dev MONGODB_URI=mongodb://localhost:27017/turbotrades JWT_SECRET=your-secret REFRESH_TOKEN_SECRET=your-secret SESSION_SECRET=your-secret STEAM_API_KEY=your-key STEAM_REALM=https://turbotrades.dev STEAM_RETURN_URL=https://api.turbotrades.dev/auth/steam/return ``` --- ## βœ… Post-Deployment Checklist - [ ] Backend is running (`pm2 list`) - [ ] Frontend loads (visit https://turbotrades.dev) - [ ] API responds (`curl https://api.turbotrades.dev/api/health`) - [ ] Steam login works - [ ] WebSocket connects - [ ] No errors in PM2 logs - [ ] No errors in Nginx logs --- ## πŸ†˜ Emergency Contacts - **PM2 Documentation:** https://pm2.keymetrics.io/docs/usage/quick-start/ - **Nginx Documentation:** https://nginx.org/en/docs/ --- ## πŸŽ‰ Done! Your TurboTrades instance is now deployed and running! - 🌐 **Frontend:** https://turbotrades.dev - πŸ”§ **Backend:** https://api.turbotrades.dev - πŸ’¬ **WebSocket:** https://ws.turbotrades.dev **Happy Trading! πŸš€**