import { RequestMethod, ValidationPipe, VersioningType } from '@nestjs/common'; import { NestExpressApplication } from '@nestjs/platform-express'; import helmet from 'helmet'; import cookieParser from 'cookie-parser'; export function configureApp(app: NestExpressApplication): void { // Trust the single reverse-proxy hop (K8s ingress) so req.ip reflects the // real client IP from X-Forwarded-For — required for per-client throttling // to work correctly rather than rate-limiting all traffic together. app.set('trust proxy', 1); app.use(helmet()); app.use(cookieParser()); app.enableCors({ origin: process.env.FRONTEND_ORIGIN ?? 'http://localhost:3000', credentials: true, }); app.setGlobalPrefix('api', { exclude: [ { path: 'health', method: RequestMethod.GET }, { path: 'health/ready', method: RequestMethod.GET }, ], }); app.enableVersioning({ type: VersioningType.URI, defaultVersion: '1' }); app.useGlobalPipes( new ValidationPipe({ whitelist: true, forbidNonWhitelisted: true, transform: true, }), ); }