70 lines
1.5 KiB
TypeScript
70 lines
1.5 KiB
TypeScript
import 'reflect-metadata';
|
|
|
|
import { ValidationPipe } from '@nestjs/common';
|
|
import { NestFactory } from '@nestjs/core';
|
|
import { NestExpressApplication } from '@nestjs/platform-express';
|
|
import cookieParser = require('cookie-parser');
|
|
import helmet from 'helmet';
|
|
|
|
import { AppModule } from './app.module';
|
|
import { ApiExceptionFilter } from './common/filters/api-exception.filter';
|
|
import { requestIdMiddleware } from './common/http/request-id.middleware';
|
|
|
|
async function bootstrap() {
|
|
const app = await NestFactory.create<NestExpressApplication>(
|
|
AppModule,
|
|
{
|
|
bufferLogs: true,
|
|
},
|
|
);
|
|
|
|
app.set('trust proxy', 1);
|
|
|
|
app.getHttpAdapter().getInstance().disable('x-powered-by');
|
|
|
|
app.use(
|
|
helmet({
|
|
contentSecurityPolicy: false,
|
|
crossOriginResourcePolicy: {
|
|
policy: 'same-site',
|
|
},
|
|
}),
|
|
);
|
|
|
|
app.use(requestIdMiddleware);
|
|
app.use(cookieParser());
|
|
|
|
app.useBodyParser('json', {
|
|
limit: '1mb',
|
|
});
|
|
|
|
app.useBodyParser('urlencoded', {
|
|
limit: '1mb',
|
|
extended: false,
|
|
});
|
|
|
|
app.useGlobalPipes(
|
|
new ValidationPipe({
|
|
whitelist: true,
|
|
forbidNonWhitelisted: true,
|
|
transform: true,
|
|
}),
|
|
);
|
|
|
|
app.useGlobalFilters(new ApiExceptionFilter());
|
|
|
|
app.setGlobalPrefix('api/v3');
|
|
|
|
app.enableShutdownHooks();
|
|
|
|
const port = Number(process.env.API_PORT ?? 3000);
|
|
|
|
await app.listen(port, '0.0.0.0');
|
|
}
|
|
|
|
bootstrap().catch((error: unknown) => {
|
|
console.error('Fatal bootstrap error');
|
|
console.error(error);
|
|
process.exit(1);
|
|
});
|