import { NestFactory } from '@nestjs/core'; import { AppModule } from './app.module'; import { ValidationPipe } from '@nestjs/common'; import { ResponseInterceptor } from './common/response.interceptor'; import { DocumentBuilder, SwaggerModule } from '@nestjs/swagger'; import helmet from 'helmet'; import { NestExpressApplication } from '@nestjs/platform-express'; import { join } from 'path'; async function bootstrap() { /** * Configura timezone para horário brasileiro */ process.env.TZ = 'America/Sao_Paulo'; const app = await NestFactory.create(AppModule); app.use(helmet({ contentSecurityPolicy: { directives: { defaultSrc: [`'self'`], scriptSrc: [`'self'`, `'unsafe-inline'`, 'cdn.jsdelivr.net', 'cdnjs.cloudflare.com'], styleSrc: [`'self'`, `'unsafe-inline'`, 'cdnjs.cloudflare.com'], imgSrc: [`'self'`, 'data:'], connectSrc: [`'self'`], fontSrc: [`'self'`, 'cdnjs.cloudflare.com'], }, }, })); // Configurar pasta de arquivos estáticos app.useStaticAssets(join(__dirname, '..', 'public'), { index: false, prefix: '/dashboard', }); app.useGlobalInterceptors(new ResponseInterceptor()); app.useGlobalPipes( new ValidationPipe({ whitelist: true, forbidNonWhitelisted: true, transform: true, transformOptions: { enableImplicitConversion: true, }, forbidUnknownValues: true, disableErrorMessages: process.env.NODE_ENV === 'production', }), ); app.enableCors({ origin: true, methods: ['GET', 'POST', 'PUT', 'DELETE', 'PATCH', 'OPTIONS'], credentials: true, allowedHeaders: ['Content-Type', 'Authorization', 'Accept'], }); const config = new DocumentBuilder() .setTitle('Portal Jurunense API') .setDescription('Documentação da API do Portal Jurunense') .setVersion('1.0') .addBearerAuth() .build(); const document = SwaggerModule.createDocument(app, config); SwaggerModule.setup('docs', app, document); await app.listen(8066); } bootstrap();