From 5666c16d00ab77df718a054b84b3a3e8dcc23f55 Mon Sep 17 00:00:00 2001 From: Mathis Date: Thu, 31 Oct 2024 11:43:49 +0100 Subject: [PATCH] Add main application bootstrap logic Introduce the main.ts file to set up the NestJS application. This includes enabling CORS, configuring Swagger documentation, and setting up global validation pipes. --- src/main.ts | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 src/main.ts diff --git a/src/main.ts b/src/main.ts new file mode 100644 index 0000000..c607338 --- /dev/null +++ b/src/main.ts @@ -0,0 +1,26 @@ +import { NestFactory } from '@nestjs/core'; +import { AppModule } from './app.module'; +import { ValidationPipe } from '@nestjs/common'; +import { DocumentBuilder, SwaggerModule } from '@nestjs/swagger'; + +async function bootstrap() { + const app = await NestFactory.create(AppModule); + app.enableCors(); + + const config = new DocumentBuilder() + .setTitle('Neptune API') + .setDescription('A fictive app') + .setVersion('1.0') + .build(); + const document = SwaggerModule.createDocument(app, config); + SwaggerModule.setup('api', app, document); + + app.useGlobalPipes( + new ValidationPipe({ + whitelist: true, + }), + ); + + await app.listen(process.env.PORT || 3000); +} +bootstrap();