Compare commits
4 Commits
2562d51725
...
5b7e361c21
| Author | SHA1 | Date | |
|---|---|---|---|
| 5b7e361c21 | |||
| 033ef4485f | |||
| 195e1f6951 | |||
| 73c939e75b |
@@ -27,6 +27,36 @@ const isDevelopment = process.env.NODE_ENV === 'development';
|
||||
|
||||
const loggingService = LoggingService.getInstance();
|
||||
|
||||
// Validate required environment variables in production
|
||||
if (process.env.NODE_ENV === 'production') {
|
||||
const requiredEnvVars = [
|
||||
'JWT_SECRET',
|
||||
'DB_PASSWORD',
|
||||
'DB_HOST',
|
||||
'DB_NAME',
|
||||
'POSTGRES_PASSWORD'
|
||||
];
|
||||
|
||||
const missingVars = requiredEnvVars.filter(varName => !process.env[varName]);
|
||||
|
||||
if (missingVars.length > 0) {
|
||||
logError('[FATAL] Missing required environment variables in production:', missingVars.join(', '));
|
||||
logError('[FATAL] Please configure all required environment variables in .env.server');
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
// Check for placeholder values that haven't been changed
|
||||
if (process.env.JWT_SECRET && process.env.JWT_SECRET.includes('CHANGE_THIS')) {
|
||||
logError('[FATAL] JWT_SECRET still contains placeholder value. Please set a proper secret in .env.server');
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
if (process.env.POSTGRES_PASSWORD && process.env.POSTGRES_PASSWORD.includes('CHANGE_THIS')) {
|
||||
logError('[FATAL] POSTGRES_PASSWORD still contains placeholder value. Please set a proper password in .env.server');
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
logStartup('SerpentRace Backend starting up', {
|
||||
environment: process.env.NODE_ENV || 'development',
|
||||
port: PORT,
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
|
||||
/* Language and Environment */
|
||||
"target": "ES2020", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
|
||||
"lib": ["ES2020"], /* Specify a set of bundled library declaration files that describe the target runtime environment. */
|
||||
// "lib": [], /* Specify a set of bundled library declaration files that describe the target runtime environment. */
|
||||
// "jsx": "preserve", /* Specify what JSX code is generated. */
|
||||
// "libReplacement": true, /* Enable lib replacement. */
|
||||
"experimentalDecorators": true, /* Enable experimental support for legacy experimental decorators. */
|
||||
|
||||
@@ -3,7 +3,7 @@ version: '3.8'
|
||||
services:
|
||||
# Backend service using pre-built image
|
||||
backend:
|
||||
image: serpentrace-backend:latest
|
||||
image: serpentrace_docker-backend:latest
|
||||
container_name: serpentrace-backend
|
||||
restart: unless-stopped
|
||||
ports:
|
||||
@@ -53,12 +53,14 @@ services:
|
||||
|
||||
# Frontend service using pre-built image
|
||||
frontend:
|
||||
image: serpentrace-frontend:latest
|
||||
image: serpentrace_docker-frontend:latest
|
||||
container_name: serpentrace-frontend
|
||||
restart: unless-stopped
|
||||
ports:
|
||||
- "80:80"
|
||||
- "443:443"
|
||||
volumes:
|
||||
- ./nginx.conf:/etc/nginx/conf.d/default.conf:ro
|
||||
depends_on:
|
||||
- backend
|
||||
networks:
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
server {
|
||||
listen 80;
|
||||
server_name localhost;
|
||||
root /usr/share/nginx/html;
|
||||
index index.html index.htm;
|
||||
|
||||
# Enable gzip compression
|
||||
gzip on;
|
||||
gzip_vary on;
|
||||
gzip_min_length 1024;
|
||||
gzip_types text/plain text/css text/xml text/javascript application/javascript application/xml+rss application/json;
|
||||
|
||||
# Security headers
|
||||
add_header X-Frame-Options "SAMEORIGIN" always;
|
||||
add_header X-Content-Type-Options "nosniff" always;
|
||||
add_header X-XSS-Protection "1; mode=block" always;
|
||||
|
||||
# Handle client routing
|
||||
location / {
|
||||
try_files $uri $uri/ /index.html;
|
||||
}
|
||||
|
||||
# API proxy to backend
|
||||
location /api/ {
|
||||
proxy_pass http://backend:3000/;
|
||||
proxy_http_version 1.1;
|
||||
proxy_set_header Upgrade $http_upgrade;
|
||||
proxy_set_header Connection 'upgrade';
|
||||
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;
|
||||
proxy_cache_bypass $http_upgrade;
|
||||
}
|
||||
|
||||
# WebSocket support
|
||||
location /socket.io/ {
|
||||
proxy_pass http://backend:3000;
|
||||
proxy_http_version 1.1;
|
||||
proxy_set_header Upgrade $http_upgrade;
|
||||
proxy_set_header Connection "upgrade";
|
||||
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;
|
||||
}
|
||||
|
||||
# Static assets caching
|
||||
location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg)$ {
|
||||
expires 1y;
|
||||
add_header Cache-Control "public, immutable";
|
||||
}
|
||||
|
||||
# Health check endpoint
|
||||
location /health {
|
||||
access_log off;
|
||||
return 200 "healthy\n";
|
||||
add_header Content-Type text/plain;
|
||||
}
|
||||
}
|
||||
Binary file not shown.
Reference in New Issue
Block a user