fix: guard Swagger /docs behind SWAGGER_ENABLED env var
This commit is contained in:
parent
765ec37c3a
commit
10fe16a7f5
1 changed files with 17 additions and 17 deletions
34
src/main.ts
34
src/main.ts
|
|
@ -1,30 +1,30 @@
|
||||||
import 'reflect-metadata';
|
import reflect-metadata;
|
||||||
import helmet from 'helmet';
|
import helmet from helmet;
|
||||||
import { ValidationPipe } from '@nestjs/common';
|
import { ValidationPipe } from @nestjs/common;
|
||||||
import { NestFactory } from '@nestjs/core';
|
import { NestFactory } from @nestjs/core;
|
||||||
import { Logger } from 'nestjs-pino';
|
import { Logger } from nestjs-pino;
|
||||||
import { SwaggerModule, DocumentBuilder } from '@nestjs/swagger';
|
import { SwaggerModule, DocumentBuilder } from @nestjs/swagger;
|
||||||
import { AppModule } from './app.module';
|
import { AppModule } from ./app.module;
|
||||||
|
|
||||||
async function bootstrap() {
|
async function bootstrap() {
|
||||||
const app = await NestFactory.create(AppModule, { bufferLogs: true });
|
const app = await NestFactory.create(AppModule, { bufferLogs: true });
|
||||||
app.useLogger(app.get(Logger));
|
app.useLogger(app.get(Logger));
|
||||||
app.use(helmet());
|
app.use(helmet());
|
||||||
// Contracte API sub /v1 (blueprint 16); health ramane la radacina pentru
|
app.setGlobalPrefix(v1, { exclude: [health] });
|
||||||
// healthcheck-urile Coolify existente.
|
|
||||||
app.setGlobalPrefix('v1', { exclude: ['health'] });
|
|
||||||
app.useGlobalPipes(
|
app.useGlobalPipes(
|
||||||
new ValidationPipe({ whitelist: true, forbidNonWhitelisted: true, transform: true }),
|
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 });
|
app.enableCors({ origin: allowedOrigins, credentials: true });
|
||||||
|
|
||||||
const config = new DocumentBuilder()
|
if (process.env.SWAGGER_ENABLED === true) {
|
||||||
.setTitle('CEO OS API')
|
const config = new DocumentBuilder()
|
||||||
.setVersion('0.1.0')
|
.setTitle(CEO OS API)
|
||||||
.build();
|
.setVersion(0.1.0)
|
||||||
const document = SwaggerModule.createDocument(app, config);
|
.build();
|
||||||
SwaggerModule.setup('docs', app, document);
|
const document = SwaggerModule.createDocument(app, config);
|
||||||
|
SwaggerModule.setup(docs, app, document);
|
||||||
|
}
|
||||||
|
|
||||||
const port = process.env.PORT ?? 3001;
|
const port = process.env.PORT ?? 3001;
|
||||||
await app.listen(port);
|
await app.listen(port);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue