import 'reflect-metadata'; import { NestFactory } from '@nestjs/core'; import { NestExpressApplication } from '@nestjs/platform-express'; import { Logger } from '@nestjs/common'; import compression from 'compression'; import helmet from 'helmet'; import path from 'node:path'; import fs from 'node:fs'; import { AppModule } from './app.module'; import { configureApp } from './setup'; import { resolveSessionSecret } from './auth/session-secret'; async function bootstrap(): Promise { const app = await NestFactory.create(AppModule, { bodyParser: true }); configureApp(app, resolveSessionSecret()); // Cross-origin clients (the Tauri shells, a dev frontend on another port) // are opt-in: CORS stays off unless CORS_ORIGINS lists them. Same-origin // browsers never need it, so the default deployment keeps the tighter // posture. const corsOrigins = (process.env.CORS_ORIGINS ?? '') .split(',') .map((o) => o.trim()) .filter(Boolean); if (corsOrigins.length) { app.enableCors({ origin: corsOrigins, credentials: true }); } // Security headers (CSP, nosniff, frame-ancestors, referrer policy, ...). The // API also serves the SPA, so these harden the frontend too. The CSP allows // the app's own origin plus what the client actually needs: // - 'unsafe-inline' styles: Svelte scopes styles via inline