if (process.env.ENV !== 'local') require('elastic-apm-node/start'); import { NestFactory } from '@nestjs/core'; import { DocumentBuilder, SwaggerModule } from '@nestjs/swagger'; import helmet from 'helmet'; import { DadosferaLogger } from '@dadosfera/dadosfera-logs'; import { AppModule } from './app.module'; import { writeFileSync } from 'fs'; import { execSync } from 'child_process'; import { INestApplication } from '@nestjs/common'; async function bootstrap() { DadosferaLogger.setupLogger({ serviceName: 'maestro', serviceEnvironment: process.env.ENV, }); const logger = new DadosferaLogger(); const app = await NestFactory.create(AppModule, { logger, cors: { origin: '*', methods: 'GET,HEAD,PUT,PATCH,POST,DELETE', preflightContinue: false, optionsSuccessStatus: 204, }, }); app.use(helmet()); configureSwagger(app); await app.listen(3333); } function configureSwagger(app: INestApplication) { let branchName = ''; try { branchName = execSync('git rev-parse --abbrev-ref HEAD') .toString() .replace('\n', '') .trim(); } catch (error) { console.log("Can't get branch name", error); } const swaggerTitle = branchName ? `Maestro - ${branchName}` : 'Maestro'; const config = new DocumentBuilder() .setTitle(swaggerTitle) .setDescription('Documentation for Maestro gateway') .addBearerAuth( { type: 'http', scheme: 'bearer', bearerFormat: 'JWT' }, 'Authorization', ) .build(); const document = SwaggerModule.createDocument(app, config); if (process.env.ENV === 'local') SwaggerModule.setup('api', app, document); writeFileSync( 'docsfera.json', JSON.stringify( { service: '${DOCS_API_TOKEN}', pageId: '${DOCS_PAGE_ID}', blockId: '${DOCS_BLOCK_ID}', schema: document, }, null, 2, ), ); } bootstrap();