49 lines
1.3 KiB
TypeScript
49 lines
1.3 KiB
TypeScript
import { randomUUID } from 'node:crypto';
|
|
|
|
import { NestFactory } from '@nestjs/core';
|
|
import {
|
|
FastifyAdapter,
|
|
NestFastifyApplication,
|
|
} from '@nestjs/platform-fastify';
|
|
import { DocumentBuilder, SwaggerModule } from '@nestjs/swagger';
|
|
import { Logger } from 'nestjs-pino';
|
|
|
|
import { validateConfig } from '@hexahost/config';
|
|
|
|
import { AppModule } from './app.module';
|
|
import { Rfc7807ExceptionFilter } from './common/filters/rfc7807-exception.filter';
|
|
|
|
async function bootstrap(): Promise<void> {
|
|
const config = validateConfig();
|
|
|
|
const app = await NestFactory.create<NestFastifyApplication>(
|
|
AppModule,
|
|
new FastifyAdapter({
|
|
genReqId: () => randomUUID(),
|
|
requestIdHeader: 'x-request-id',
|
|
requestIdLogLabel: 'requestId',
|
|
}),
|
|
{
|
|
bufferLogs: true,
|
|
},
|
|
);
|
|
|
|
app.useLogger(app.get(Logger));
|
|
app.setGlobalPrefix('api/v1');
|
|
app.useGlobalFilters(new Rfc7807ExceptionFilter());
|
|
|
|
const swaggerConfig = new DocumentBuilder()
|
|
.setTitle(config.APP_NAME)
|
|
.setDescription('HexaHost GameCloud REST API')
|
|
.setVersion('0.0.0')
|
|
.addServer(config.API_URL)
|
|
.build();
|
|
|
|
const document = SwaggerModule.createDocument(app, swaggerConfig);
|
|
SwaggerModule.setup('api/v1/docs', app, document);
|
|
|
|
await app.listen(config.API_PORT, '0.0.0.0');
|
|
}
|
|
|
|
void bootstrap();
|