59 lines
1.9 KiB
TypeScript
59 lines
1.9 KiB
TypeScript
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(); |