import { HttpAdapterHost, NestFactory } from '@nestjs/core' import { ValidationPipe } from '@nestjs/common' import { ConfigService } from '@nestjs/config' import { DocumentBuilder, SwaggerModule } from '@nestjs/swagger' import { PrismaClientExceptionFilter, PrismaService } from 'nestjs-prisma' import { JwtExceptionsFilter } from './common/filters/jwt-exceptions.filter' import { AppModule } from './app.module' async function bootstrap() { const app = await NestFactory.create(AppModule) // Validation app.useGlobalPipes(new ValidationPipe({ whitelist: true })) // enable shutdown hook const prismaService = app.get(PrismaService) await prismaService.enableShutdownHooks(app) // Prisma Client Exception Filter for unhandled exceptions const { httpAdapter } = app.get(HttpAdapterHost) app.useGlobalFilters(new PrismaClientExceptionFilter(httpAdapter)) app.useGlobalFilters(new JwtExceptionsFilter(httpAdapter)) // Swagger Api const options = new DocumentBuilder() .addBearerAuth() .setTitle('Nest Project') .setDescription('The Nest-Project API description') .setVersion('1.0') .build() const document = SwaggerModule.createDocument(app, options) SwaggerModule.setup('api', app, document) const configService = app.get(ConfigService) const PORT = configService.get('nest.port', 12400) await app.listen(PORT) } bootstrap()