Files
mtusi2026lab3-fork/src/main.ts
T
qrtx 24f32c3fbe feat(api): implement persistent messaging and graceful draining
Add shared sessions, cached message history and transactional idempotency backed by PostgreSQL. Return readiness 503 during draining and finish in-flight requests before closing dependencies.
2026-10-29 11:46:28 +03:00

57 lines
1.4 KiB
TypeScript

import { NestFactory } from '@nestjs/core';
import { NestFastifyApplication } from '@nestjs/platform-fastify';
import { DocumentBuilder, SwaggerModule } from '@nestjs/swagger';
import { apiReference } from '@scalar/nestjs-api-reference';
import { AppModule } from './app.module';
import { Logger } from 'nestjs-pino';
import {
createFastifyAdapter,
DRAIN_DELAY_MS,
exposeRequestIdHeader,
} from './common/http/fastify-adapter';
async function bootstrap() {
const app = await NestFactory.create<NestFastifyApplication>(
AppModule,
createFastifyAdapter(DRAIN_DELAY_MS),
{
bufferLogs: true,
},
);
exposeRequestIdHeader(app);
app.useLogger(app.get(Logger));
app.enableShutdownHooks();
const swaggerConfig = new DocumentBuilder()
.setTitle('Messenger API')
.setDescription('Документация API')
.setVersion('1.3.0')
.addBasicAuth({ type: 'http', scheme: 'basic' }, 'basicAuth')
.addBearerAuth(
{ type: 'http', scheme: 'bearer', bearerFormat: 'opaque' },
'bearerAuth',
)
.build();
const document = SwaggerModule.createDocument(app, swaggerConfig);
SwaggerModule.setup('swagger', app, document);
app.use(
'/docs',
apiReference({
content: document,
theme: 'laserwave',
withFastify: true,
}),
);
await app.listen(
Number(process.env.APP_PORT ?? process.env.PORT ?? 8080),
process.env.APP_HOST ?? '0.0.0.0',
);
}
void bootstrap();