main.ts 987 B

123456789101112131415161718192021222324252627282930
  1. import { NestFactory } from '@nestjs/core';
  2. import { AppModule } from './app.module';
  3. import { DocumentBuilder, SwaggerModule } from '@nestjs/swagger';
  4. import { ValidationPipe } from '@nestjs/common';
  5. import { ErrorsInterceptor } from './interceptor/errors.interceptor';
  6. import mainConfig from 'config.json';
  7. async function bootstrap() {
  8. const app = await NestFactory.create(AppModule);
  9. app.useGlobalPipes(new ValidationPipe());
  10. app.useGlobalInterceptors(new ErrorsInterceptor());
  11. app.setGlobalPrefix('api');
  12. app.enableCors({
  13. origin: mainConfig.cors,
  14. credentials: true,
  15. exposedHeaders: ['set-cookie'],
  16. });
  17. // SWAGGER
  18. const config = new DocumentBuilder()
  19. .setTitle(process.env.npm_package_name)
  20. .setDescription('Base nest js')
  21. .setVersion(process.env.npm_package_version)
  22. .build();
  23. const document = SwaggerModule.createDocument(app, config);
  24. SwaggerModule.setup('api', app, document);
  25. await app.listen(mainConfig.port);
  26. }
  27. bootstrap();