From a3b29e6cc2e65b718b8244191f68a6119d5ca079 Mon Sep 17 00:00:00 2001 From: admin-valentin Date: Fri, 31 Jul 2026 10:32:52 +0000 Subject: [PATCH] fix: guard Swagger /docs behind SWAGGER_ENABLED env var --- src/main.ts | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/src/main.ts b/src/main.ts index 4f60a16..0542ad6 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1,29 +1,29 @@ -import reflect-metadata; -import helmet from helmet; -import { ValidationPipe } from @nestjs/common; -import { NestFactory } from @nestjs/core; -import { Logger } from nestjs-pino; -import { SwaggerModule, DocumentBuilder } from @nestjs/swagger; -import { AppModule } from ./app.module; +import 'reflect-metadata'; +import helmet from 'helmet'; +import { ValidationPipe } from '@nestjs/common'; +import { NestFactory } from '@nestjs/core'; +import { Logger } from 'nestjs-pino'; +import { SwaggerModule, DocumentBuilder } from '@nestjs/swagger'; +import { AppModule } from './app.module'; async function bootstrap() { const app = await NestFactory.create(AppModule, { bufferLogs: true }); app.useLogger(app.get(Logger)); app.use(helmet()); - app.setGlobalPrefix(v1, { exclude: [health] }); + app.setGlobalPrefix('v1', { exclude: ['health'] }); app.useGlobalPipes( new ValidationPipe({ whitelist: true, forbidNonWhitelisted: true, transform: true }), ); - const allowedOrigins = (process.env.CORS_ORIGINS ?? http://localhost:3000).split(,).map((o) => o.trim()); + const allowedOrigins = (process.env.CORS_ORIGINS ?? 'http://localhost:3000').split(',').map((o) => o.trim()); app.enableCors({ origin: allowedOrigins, credentials: true }); - if (process.env.SWAGGER_ENABLED === true) { + if (process.env.SWAGGER_ENABLED === 'true') { const config = new DocumentBuilder() - .setTitle(CEO OS API) - .setVersion(0.1.0) + .setTitle('CEO OS API') + .setVersion('0.1.0') .build(); const document = SwaggerModule.createDocument(app, config); - SwaggerModule.setup(docs, app, document); + SwaggerModule.setup('docs', app, document); } const port = process.env.PORT ?? 3001;