Fix: Use .js extension for entities in production, fix nginx proxy path

This commit is contained in:
Donat Magda
2025-11-26 00:05:06 +01:00
parent 8c27b5ea2f
commit 5eb4d3eef7
2 changed files with 65 additions and 2 deletions
@@ -1,6 +1,9 @@
import { DataSource } from 'typeorm'; import { DataSource } from 'typeorm';
import { join } from 'path'; 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({ export const AppDataSource = new DataSource({
type: 'postgres', type: 'postgres',
host: process.env.DB_HOST || 'localhost', host: process.env.DB_HOST || 'localhost',
@@ -10,8 +13,8 @@ export const AppDataSource = new DataSource({
database: process.env.DB_NAME || 'serpentrace', database: process.env.DB_NAME || 'serpentrace',
synchronize: false, // Set to false when using migrations synchronize: false, // Set to false when using migrations
logging: process.env.NODE_ENV === 'development', logging: process.env.NODE_ENV === 'development',
entities: [join(__dirname, '../Domain/**/*Aggregate.ts')], entities: [join(__dirname, `../Domain/**/*Aggregate.${ext}`)],
migrations: [join(__dirname, './Migrations/*.ts')], migrations: [join(__dirname, `./Migrations/*.${ext}`)],
migrationsTableName: 'migrations', migrationsTableName: 'migrations',
migrationsRun: false // Let migrations run manually migrationsRun: false // Let migrations run manually
}); });
+60
View File
@@ -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;
}
}