main.ts 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. import { NestFactory, PartialGraphHost } from '@nestjs/core'
  2. import { AppModule } from './app.module'
  3. import { Logger, ValidationPipe } from '@nestjs/common'
  4. import { ConfigService } from '@nestjs/config'
  5. import { configureSwaggerDocs } from './helpers/configure-swagger-docs.helper'
  6. import * as fs from 'fs'
  7. async function bootstrap() {
  8. const app = await NestFactory.create(AppModule, {
  9. snapshot: true,
  10. abortOnError: false
  11. })
  12. const configService = app.get<ConfigService>(ConfigService)
  13. app.setGlobalPrefix('api')
  14. app.useGlobalPipes(
  15. new ValidationPipe({
  16. whitelist: false,
  17. transform: true,
  18. forbidNonWhitelisted: false,
  19. transformOptions: {
  20. enableImplicitConversion: true
  21. }
  22. })
  23. )
  24. configureSwaggerDocs(app, configService)
  25. app.enableCors({
  26. origin: true,
  27. methods: 'GET,POST,PUT,PATCH,DELETE',
  28. credentials: true
  29. })
  30. const port = configService.get<number>('NODE_API_PORT') || 3000
  31. await app.listen(port)
  32. Logger.log(`Url for OpenApi: ${await app.getUrl()}/docs`, 'Swagger')
  33. }
  34. bootstrap().catch((err) => {
  35. fs.writeFileSync('graph.json', PartialGraphHost.toString() ?? '')
  36. process.exit(1)
  37. })