🖥️ Hosting
To host your project on a server, please use Nginx.
🛠️ 1. .env
Configuration
.env
ConfigurationUpdate the .env
file with your production values:
NODE_ENV=production # ✅ Ensures optimized builds
SECURE=true # ✅ Enables HTTPS-aware logic
SERVER_IP=localhost # ✅ Keep as localhost for Nginx to proxy correctly
PORT=3000 # ✅ Optional: change port if needed
DNS=https://yourdomain.com # ✅ Set this to your real domain
REDIS_HOST=127.0.0.1 # ✅ Make sure Redis is running on this ip
REDIS_PORT=6379 # ✅ Make sure Redis is running on this port
# ✅ OAuth client configs (e.g., Google, Github)
CLIENT_ID=...
CLIENT_SECRET=...
DATABASE_URL="mysql://root:@localhost:3306/yourDB"
⚠️ For OAuth, update the redirect URL in each provider’s dashboard to match your real DNS.
💡 Recommended: Keep your database hosted locally (i.e.,
localhost
) for optimal performance.
🧾 2. Update config.ts
config.ts
Inside your project’s config.ts
, update the backend URL to reflect your domain:
export const backendURL = "https://yourdomain.com";
📦 3. Build the App
Run the build process for production:
npm run build
This will internally run:
npm run buildClient
npm run buildServer
✅ These commands only succeed if your code has no unused or invalid values. Clean up or adjust your code if needed (the terminal will tell you what is wrong).
If the build completes successfully, you’ll find everything in the dst/
directory.
📂 4. Serve with Nginx
Your Nginx config should point to the dst/server.js
file using a reverse proxy.
Here’s a complete working example (including Socket.IO support):
# Subdomain (test.yourDomain.com)
server {
server_name test.yourDomain.com;
location / {
proxy_pass http://localhost:3000;
# WebSocket and headers settings
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;
}
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/test.yourDomain.com/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/test.yourDomain.com/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
}
# Redirect non-SSL traffic to SSL for test.yourDomain.com
server {
if ($host = test.yourDomain.com) {
return 301 https://$host$request_uri;
} # managed by Certbot
listen 80;
server_name test.yourDomain.com;
return 404; # managed by Certbot
}
This Nginx configuration sets up a secure reverse proxy for your Node.js application running locally on port 3000
. It includes:
✅ HTTPS support via SSL
🔄 WebSocket (Socket.IO) compatibility
🔁 Automatic redirection from HTTP → HTTPS
⚙️ Important Notes
🧠 Make sure the
PORT
in your.env
file matches the port used in the Nginx config.🔐 You’ll need to generate your own SSL certificates (e.g., with Let’s Encrypt).
📁 Update the
ssl_certificate
andssl_certificate_key
file paths to match your certificate locations.
✅ Final Checklist
Last updated