nest-project/src/main.ts

27 lines
877 B
TypeScript
Raw Normal View History

2023-02-15 19:12:21 +08:00
import { HttpAdapterHost, NestFactory } from '@nestjs/core'
import { ValidationPipe } from '@nestjs/common'
2023-02-15 20:03:13 +08:00
import { ConfigService } from '@nestjs/config'
2023-02-15 19:12:21 +08:00
import { PrismaClientExceptionFilter, PrismaService } from 'nestjs-prisma'
import { AppModule } from './app.module'
2023-02-15 16:49:40 +08:00
async function bootstrap() {
const app = await NestFactory.create(AppModule)
2023-02-15 19:12:21 +08:00
// Validation
app.useGlobalPipes(new ValidationPipe({ whitelist: true }))
2023-02-15 19:12:21 +08:00
// 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))
2023-02-15 20:03:13 +08:00
const configService = app.get(ConfigService)
const PORT = configService.get<number>('PORT', 12400)
await app.listen(PORT)
2023-02-15 16:49:40 +08:00
}
bootstrap()