Production Deployment Guide
Deploying Roofstick to a production environment requires configuring the backend, building the frontend, and serving the files securely over HTTPS.
1. Prerequisites
- A VPS or Dedicated Server running Linux (Ubuntu 20.04/22.04 recommended).
- Domain Name pointed to your server's IP address.
- Root or Sudo SSH access.
2. Server Setup & MongoDB
- Install Node.js (v16.x or v18.x) and
npm/yarn. - Install MongoDB Server locally, or use a cloud database like MongoDB Atlas.
- Install a process manager:
npm install -g pm2. - Install Nginx:
sudo apt install nginx.
3. Backend Deployment
- Upload the backend source code to your server (e.g.,
/var/www/roofstick-backend). - Run
npm installoryarn installto install dependencies. - Configure the
.envfile:- Set
NODE_ENV=production. - Set
PORT=5000(or your preferred port). - Configure
MONGODB_URIandJWT_SECRET.
- Set
- Start the backend using PM2:
pm2 start server.js --name "roofstick-api"pm2 savepm2 startup
4. Frontend Build & Deployment
- Upload the frontend source code to a separate directory (e.g.,
/var/www/roofstick-frontend). - Run
npm installoryarn install. - Configure the frontend
.envfile. EnsureREACT_APP_API_URLpoints to your domain (e.g.,https://api.yourdomain.com). - Build the project:
npm run build
- The built static files will be located in the
buildoroutfolder. Move or point Nginx to this folder.
5. Domain Setup & Nginx Configuration
Create two Nginx server blocks (one for the frontend and one for the backend API).
Backend API Configuration (e.g., api.yourdomain.com)
server {
server_name api.yourdomain.com;
location / {
proxy_pass http://localhost:5000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
}
Frontend Configuration (e.g., yourdomain.com)
server {
server_name yourdomain.com www.yourdomain.com;
location / {
proxy_pass http://localhost:3999; # Ensure this matches your Next.js port
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
}
6. SSL/HTTPS
Secure your domains using Let's Encrypt (Certbot).
sudo apt install certbot python3-certbot-nginx
sudo certbot --nginx -d yourdomain.com -d www.yourdomain.com
sudo certbot --nginx -d api.yourdomain.com
7. Application Start & Restart
Whenever you make changes or update the environment variables:
- Backend:
pm2 restart roofstick-api - Frontend: You must rebuild the frontend (
npm run build) for.envchanges to take effect. No PM2 restart is needed for static files.