forked from mtusi2026/mtusi2026lab2
feat: lab2 done
This commit is contained in:
+15
-14
@@ -1,23 +1,26 @@
|
||||
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 { ApiExceptionFilter } from './common/errors/api-exception.filter.js';
|
||||
import { MetricsService } from './metrics/metrics.service.js';
|
||||
import { RequestIdInterceptor } from './common/http/request-id.interceptor.js';
|
||||
|
||||
async function bootstrap() {
|
||||
async function bootstrap(): Promise<void> {
|
||||
const app = await NestFactory.create<NestFastifyApplication>(
|
||||
AppModule,
|
||||
new FastifyAdapter({
|
||||
logger: true,
|
||||
}),
|
||||
new FastifyAdapter({ logger: true }),
|
||||
);
|
||||
app.useGlobalInterceptors(
|
||||
new RequestIdInterceptor(
|
||||
app.get(HttpAdapterHost),
|
||||
app.get(MetricsService),
|
||||
),
|
||||
);
|
||||
|
||||
app.useGlobalInterceptors(new RequestIdInterceptor());
|
||||
app.useGlobalFilters(new ApiExceptionFilter());
|
||||
app.useGlobalPipes(
|
||||
new ValidationPipe({
|
||||
whitelist: true,
|
||||
@@ -27,12 +30,10 @@ async function bootstrap() {
|
||||
);
|
||||
app.enableShutdownHooks();
|
||||
|
||||
const port = Number(process.env.APP_PORT ?? '8080');
|
||||
const host = process.env.APP_HOST ?? '0.0.0.0';
|
||||
if (!Number.isInteger(port) || port < 1 || port > 65535) {
|
||||
throw new Error('APP_PORT must be an integer between 1 and 65535');
|
||||
}
|
||||
|
||||
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();
|
||||
|
||||
Reference in New Issue
Block a user