trust-module-backend/src/main.ts

59 lines
1.9 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
import { SwaggerModule, DocumentBuilder } from '@nestjs/swagger';
import { Logger } from '@nestjs/common';
async function bootstrap() {
const app = await NestFactory.create(AppModule);
const logger = new Logger('Bootstrap');
// Установка глобального префикса для всех маршрутов
app.setGlobalPrefix('api');
// Настройка Swagger
const config = new DocumentBuilder()
.setTitle('МУФ API')
.setDescription('API для сбора метрик и аутентификации')
.setVersion('1.0')
.addBearerAuth(
{
type: 'http',
scheme: 'bearer',
bearerFormat: 'JWT',
name: 'JWT',
description: 'Enter JWT token',
in: 'header',
},
'JWT-auth', // Это имя для схемы безопасности
)
.addCookieAuth('access_token') // Для cookie-based аутентификации
.build();
const document = SwaggerModule.createDocument(app, config);
SwaggerModule.setup('api/docs', app, document, {
swaggerOptions: {
persistAuthorization: true,
tagsSorter: 'alpha',
operationsSorter: 'alpha',
docExpansion: 'none',
filter: true,
},
customSiteTitle: 'MSF API Documentation',
});
// Настройка CORS
app.enableCors({
origin: [process.env.FRONTEND_URL, "http://dev.msf.enode"],
credentials: true,
methods: 'GET,HEAD,PUT,PATCH,POST,DELETE,OPTIONS',
allowedHeaders: 'Content-Type, Authorization, X-Requested-With',
exposedHeaders: 'Authorization',
preflightContinue: false,
optionsSuccessStatus: 204
});
const port = process.env.PORT ?? 3000;
await app.listen(port);
logger.log(`Application is running on: http://localhost:${port}/api/docs`);
}
bootstrap();