From 5eb4d3eef78146f4fc56fe7d8a3a94f90e47536f Mon Sep 17 00:00:00 2001 From: Donat Magda Date: Wed, 26 Nov 2025 00:05:06 +0100 Subject: [PATCH] Fix: Use .js extension for entities in production, fix nginx proxy path --- .../src/Infrastructure/ormconfig.ts | 7 ++- deployment/nginx.conf | 60 +++++++++++++++++++ 2 files changed, 65 insertions(+), 2 deletions(-) create mode 100644 deployment/nginx.conf diff --git a/SerpentRace_Backend/src/Infrastructure/ormconfig.ts b/SerpentRace_Backend/src/Infrastructure/ormconfig.ts index 939b2117..7319375b 100644 --- a/SerpentRace_Backend/src/Infrastructure/ormconfig.ts +++ b/SerpentRace_Backend/src/Infrastructure/ormconfig.ts @@ -1,6 +1,9 @@ import { DataSource } from 'typeorm'; import { join } from 'path'; +// Use .js extension in production (compiled) and .ts in development +const ext = __filename.endsWith('.js') ? 'js' : 'ts'; + export const AppDataSource = new DataSource({ type: 'postgres', host: process.env.DB_HOST || 'localhost', @@ -10,8 +13,8 @@ export const AppDataSource = new DataSource({ database: process.env.DB_NAME || 'serpentrace', synchronize: false, // Set to false when using migrations logging: process.env.NODE_ENV === 'development', - entities: [join(__dirname, '../Domain/**/*Aggregate.ts')], - migrations: [join(__dirname, './Migrations/*.ts')], + entities: [join(__dirname, `../Domain/**/*Aggregate.${ext}`)], + migrations: [join(__dirname, `./Migrations/*.${ext}`)], migrationsTableName: 'migrations', migrationsRun: false // Let migrations run manually }); \ No newline at end of file diff --git a/deployment/nginx.conf b/deployment/nginx.conf new file mode 100644 index 00000000..03aa2417 --- /dev/null +++ b/deployment/nginx.conf @@ -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; + } +}