UNPKG

create-nest-template-malahimdev

Version:

Scaffolds a NestJS template with Swagger, global pipes, exception filters, MongoDB connection and response helpers.

48 lines (43 loc) 1.46 kB
import { NestFactory } from '@nestjs/core'; import { AppModule } from './app.module'; import { ConfigService } from '@nestjs/config'; import { DocumentBuilder, SwaggerModule } from '@nestjs/swagger'; import { ValidationPipe } from '@nestjs/common'; import { SwaggerTheme, SwaggerThemeNameEnum } from 'swagger-themes'; async function bootstrap() { const app = await NestFactory.create(AppModule); app.enableCors({ origin: ['http://localhost:3000', 'https://malahim.dev'], credentials: true, }); app.useGlobalPipes( new ValidationPipe({ whitelist: true, forbidNonWhitelisted: true, transform: true, }), ); const config = new DocumentBuilder() .setTitle('Startup Template') .setDescription('Generated by Malahim Haseeb') .setVersion('1.0') .addTag('startup') .addBearerAuth() .build(); const documentFactory = () => SwaggerModule.createDocument(app, config); const theme = new SwaggerTheme(); const optionsV1 = { explorer: true, customCss: theme.getBuffer(SwaggerThemeNameEnum.MATERIAL) }; const optionsV2 = { explorer: true, customCss: theme.getBuffer(SwaggerThemeNameEnum.DRACULA) }; SwaggerModule.setup('docs', app, documentFactory, optionsV1); SwaggerModule.setup('docsdark', app, documentFactory, optionsV2); const configService = app.get(ConfigService); const port = configService.get<number>('PORT') || 3000; await app.listen(port); } bootstrap();