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 21:26:41 +08:00
|
|
|
import { DocumentBuilder, SwaggerModule } from '@nestjs/swagger'
|
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 21:26:41 +08:00
|
|
|
// Swagger Api
|
|
|
|
const options = new DocumentBuilder()
|
2023-02-16 16:41:34 +08:00
|
|
|
.addBearerAuth()
|
2023-02-15 21:26:41 +08:00
|
|
|
.setTitle('Nest Project')
|
|
|
|
.setDescription('The Nest-Project API description')
|
|
|
|
.setVersion('1.0')
|
|
|
|
.build()
|
|
|
|
const document = SwaggerModule.createDocument(app, options)
|
|
|
|
SwaggerModule.setup('api', app, document)
|
|
|
|
|
2023-02-15 20:03:13 +08:00
|
|
|
const configService = app.get(ConfigService)
|
2023-02-21 11:13:21 +08:00
|
|
|
const PORT = configService.get<number>('nest.port', 12400)
|
2023-02-15 20:03:13 +08:00
|
|
|
|
|
|
|
await app.listen(PORT)
|
2023-02-15 16:49:40 +08:00
|
|
|
}
|
2023-02-15 17:03:08 +08:00
|
|
|
bootstrap()
|