| 10 | import { AppModule } from './app.module'; |
| 11 | |
| 12 | async function bootstrap() { |
| 13 | await enforceVersionCheck(); |
| 14 | const app = await NestFactory.create(AppModule, { |
| 15 | logger: ['log', 'error', 'warn'], |
| 16 | }); |
| 17 | |
| 18 | // Enable cookie parsing for session auth |
| 19 | app.use(cookieParser()); |
| 20 | |
| 21 | // Set global prefix for all routes |
| 22 | app.setGlobalPrefix('api/v1'); |
| 23 | |
| 24 | // Enable graceful shutdown hooks |
| 25 | app.enableShutdownHooks(); |
| 26 | |
| 27 | const httpAdapter = app.getHttpAdapter().getInstance(); |
| 28 | if (httpAdapter?.set) { |
| 29 | httpAdapter.set('etag', false); |
| 30 | } |
| 31 | |
| 32 | // Enable CORS for frontend |
| 33 | // Build dynamic origin list for multi-instance dev (instances 0-9) |
| 34 | const instanceOrigins: string[] = []; |
| 35 | for (let i = 0; i <= 9; i++) { |
| 36 | const frontendPort = 5173 + i * 100; |
| 37 | const backendPort = 3211 + i * 100; |
| 38 | instanceOrigins.push(`http://localhost:${frontendPort}`); |
| 39 | instanceOrigins.push(`http://127.0.0.1:${frontendPort}`); |
| 40 | instanceOrigins.push(`http://localhost:${backendPort}`); |
| 41 | instanceOrigins.push(`http://127.0.0.1:${backendPort}`); |
| 42 | } |
| 43 | |
| 44 | app.enableCors({ |
| 45 | origin: [ |
| 46 | 'http://localhost', |
| 47 | 'http://localhost:80', |
| 48 | 'http://localhost:8090', |
| 49 | 'https://studio.shipsec.ai', |
| 50 | ...instanceOrigins, |
| 51 | ], |
| 52 | credentials: true, |
| 53 | methods: ['GET', 'POST', 'PUT', 'DELETE', 'PATCH', 'OPTIONS'], |
| 54 | allowedHeaders: [ |
| 55 | 'Content-Type', |
| 56 | 'Authorization', |
| 57 | 'Accept', |
| 58 | 'Cache-Control', |
| 59 | 'x-organization-id', |
| 60 | 'X-Real-IP', |
| 61 | 'X-Forwarded-For', |
| 62 | 'X-Forwarded-Proto', |
| 63 | ], |
| 64 | }); |
| 65 | const port = Number(process.env.PORT ?? 3211); |
| 66 | const host = process.env.HOST ?? '0.0.0.0'; |
| 67 | |
| 68 | const config = new DocumentBuilder() |
| 69 | .setTitle('ShipSec Studio API') |