2023-02-15 19:12:21 +08:00
|
|
|
import { HttpAdapterHost, NestFactory } from '@nestjs/core'
|
2023-02-15 20:44:32 +08:00
|
|
|
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'
|
2023-02-15 17:03:08 +08:00
|
|
|
import { AppModule } from './app.module'
|
2023-02-15 16:49:40 +08:00
|
|
|
|
|
|
|
async function bootstrap() {
|
2023-02-15 17:03:08 +08:00
|
|
|
const app = await NestFactory.create(AppModule)
|
2023-02-15 19:12:21 +08:00
|
|
|
|
2023-02-15 20:44:32 +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
|
|
|
}
|
2023-02-15 17:03:08 +08:00
|
|
|
bootstrap()
|