manicanldes-backend/src/configure-app.ts

31 lines
1.1 KiB
TypeScript

import type { INestApplication } from '@nestjs/common';
import type { NestExpressApplication } from '@nestjs/platform-express';
import helmet from 'helmet';
import { randomUUID } from 'node:crypto';
import type { Request, Response, NextFunction } from 'express';
import type { Environment } from './config/environment';
import { ApiExceptionFilter } from './common/errors/api-exception.filter';
export function configureApp(
app: INestApplication,
environment: Environment,
): void {
app.setGlobalPrefix('api/v1');
app.use(helmet());
app.use((_request: Request, response: Response, next: NextFunction) => {
response.locals.requestId = randomUUID();
response.setHeader('X-Request-Id', response.locals.requestId);
response.setHeader('Cache-Control', 'no-store');
next();
});
(app as NestExpressApplication).useBodyParser('json', { limit: '32kb' });
(app as NestExpressApplication).useBodyParser('urlencoded', {
limit: '32kb',
extended: false,
parameterLimit: 100,
});
app.useGlobalFilters(new ApiExceptionFilter());
app.enableCors({ origin: environment.CORS_ORIGINS, credentials: true });
app.enableShutdownHooks();
}