forked from mtusi2026/mtusi2026lab2
40 lines
1.1 KiB
TypeScript
40 lines
1.1 KiB
TypeScript
import { NestFactory } from '@nestjs/core';
|
|
import { HttpAdapterHost } from '@nestjs/core';
|
|
import { ConfigService } from '@nestjs/config';
|
|
import { ValidationPipe } from '@nestjs/common';
|
|
import {
|
|
FastifyAdapter,
|
|
NestFastifyApplication,
|
|
} from '@nestjs/platform-fastify';
|
|
import { AppModule } from './app.module.js';
|
|
import { MetricsService } from './metrics/metrics.service.js';
|
|
import { RequestIdInterceptor } from './common/http/request-id.interceptor.js';
|
|
|
|
async function bootstrap(): Promise<void> {
|
|
const app = await NestFactory.create<NestFastifyApplication>(
|
|
AppModule,
|
|
new FastifyAdapter({ logger: true }),
|
|
);
|
|
app.useGlobalInterceptors(
|
|
new RequestIdInterceptor(
|
|
app.get(HttpAdapterHost),
|
|
app.get(MetricsService),
|
|
),
|
|
);
|
|
app.useGlobalPipes(
|
|
new ValidationPipe({
|
|
whitelist: true,
|
|
forbidNonWhitelisted: true,
|
|
transform: true,
|
|
}),
|
|
);
|
|
app.enableShutdownHooks();
|
|
|
|
const config = app.get(ConfigService);
|
|
const port = config.getOrThrow<number>('APP_PORT');
|
|
const host = config.getOrThrow<string>('APP_HOST');
|
|
await app.listen(port, host);
|
|
}
|
|
|
|
await bootstrap();
|