Files
mtusi2026lab6/src/main.ts
T

40 lines
1.1 KiB
TypeScript

import './telemetry/register';
import { Logger } from '@nestjs/common';
import { NestFactory } from '@nestjs/core';
import {
FastifyAdapter,
NestFastifyApplication,
} from '@nestjs/platform-fastify';
import { AppModule } from './app.module';
import { configureApp } from './configure-app';
import { setupSwagger } from './docs/swagger';
import { enableGracefulShutdown } from './health/shutdown';
import { registerHttpTelemetry } from './telemetry/http';
import { JsonLogger } from './telemetry/json-logger';
async function bootstrap(): Promise<void> {
const app = await NestFactory.create<NestFastifyApplication>(
AppModule,
new FastifyAdapter(),
{
bufferLogs: true,
logger: new JsonLogger(),
},
);
configureApp(app);
registerHttpTelemetry(app.getHttpAdapter().getInstance());
setupSwagger(app);
enableGracefulShutdown(app);
const host = process.env.APP_HOST ?? '0.0.0.0';
const port = Number(process.env.APP_PORT ?? 8080);
await app.listen(port, host);
Logger.log(`Listening on http://${host}:${port}`, 'Bootstrap');
}
bootstrap().catch((error) => {
Logger.error('Fatal error during bootstrap', error);
process.exit(1);
});