@@ -6,68 +6,60 @@ import { AppModule } from './app.module';
66import { HttpExceptionFilter } from './filters/http-exception.filter' ;
77
88async function bootstrap ( ) {
9- try {
10- const app = await NestFactory . create ( AppModule , {
11- // Não abortar se o banco não conectar imediatamente
12- abortOnError : false ,
13- } ) ;
14-
15- // Configuração do cookie parser
16- app . use ( cookieParser ( ) ) ;
17-
18- // Configuração do CORS
19- app . enableCors ( {
20- origin : true , // Permite todas as origens ou configure com um array de origens específicas
21- methods : 'GET,HEAD,PUT,PATCH,POST,DELETE' ,
22- credentials : true ,
23- } ) ;
9+ const app = await NestFactory . create ( AppModule ) ;
2410
25- app . useGlobalPipes (
26- new ValidationPipe ( {
27- transform : true ,
28- whitelist : true ,
29- forbidNonWhitelisted : true ,
30- } ) ,
31- ) ;
11+ // Configuração do cookie parser
12+ app . use ( cookieParser ( ) ) ;
3213
33- try {
34- const config = new DocumentBuilder ( )
35- . setTitle ( 'API Sistema Proae' )
36- . setDescription ( 'A Documentação da API do sistema proae.' )
37- . setVersion ( '1.0' )
38- . addBearerAuth ( )
39- . build ( ) ;
14+ // Configuração do CORS
15+ app . enableCors ( {
16+ origin : true , // Permite todas as origens ou configure com um array de origens específicas
17+ methods : 'GET,HEAD,PUT,PATCH,POST,DELETE' ,
18+ credentials : true ,
19+ } ) ;
4020
41- const document = SwaggerModule . createDocument ( app , config ) ;
21+ app . useGlobalPipes (
22+ new ValidationPipe ( {
23+ transform : true ,
24+ whitelist : true ,
25+ forbidNonWhitelisted : true ,
26+ } ) ,
27+ ) ;
4228
43- SwaggerModule . setup ( 'api' , app , document , {
44- swaggerOptions : {
45- persistAuthorization : true ,
46- } ,
47- customSiteTitle : 'API PROAE' ,
48- customfavIcon : '/favicon.ico' ,
49- customJs : [
50- 'https://cdnjs.cloudflare.com/ajax/libs/swagger-ui/4.15.5/swagger-ui-bundle.js' ,
51- 'https://cdnjs.cloudflare.com/ajax/libs/swagger-ui/4.15.5/swagger-ui-standalone-preset.js' ,
52- ] ,
53- customCssUrl : [
54- 'https://cdnjs.cloudflare.com/ajax/libs/swagger-ui/4.15.5/swagger-ui.css' ,
55- ] ,
56- } ) ;
57- } catch ( error ) {
58- console . error ( 'Erro ao configurar Swagger:' , error ) ;
59- }
29+ try {
30+ const config = new DocumentBuilder ( )
31+ . setTitle ( 'API Sistema Proae' )
32+ . setDescription ( 'A Documentação da API do sistema proae.' )
33+ . setVersion ( '1.0' )
34+ . addBearerAuth ( )
35+ . build ( ) ;
6036
61- // Aplicando o filter globalmente
62- app . useGlobalFilters ( new HttpExceptionFilter ( ) ) ;
37+ const document = SwaggerModule . createDocument ( app , config ) ;
6338
64- const port = process . env . PORT || 3000 ;
65- await app . listen ( port , '0.0.0.0' ) ; // Escuta em todas as interfaces
66- console . log ( `✅ Aplicação rodando na porta ${ port } ` ) ;
39+ SwaggerModule . setup ( 'api' , app , document , {
40+ swaggerOptions : {
41+ persistAuthorization : true ,
42+ } ,
43+ customSiteTitle : 'API PROAE' ,
44+ customfavIcon : '/favicon.ico' ,
45+ customJs : [
46+ 'https://cdnjs.cloudflare.com/ajax/libs/swagger-ui/4.15.5/swagger-ui-bundle.js' ,
47+ 'https://cdnjs.cloudflare.com/ajax/libs/swagger-ui/4.15.5/swagger-ui-standalone-preset.js' ,
48+ ] ,
49+ customCssUrl : [
50+ 'https://cdnjs.cloudflare.com/ajax/libs/swagger-ui/4.15.5/swagger-ui.css' ,
51+ ] ,
52+ } ) ;
6753 } catch ( error ) {
68- console . error ( '❌ Erro ao iniciar aplicação:' , error ) ;
69- process . exit ( 1 ) ;
54+ console . error ( 'Erro ao configurar Swagger:' , error ) ;
7055 }
56+
57+ // Aplicando o filter globalmente
58+ app . useGlobalFilters ( new HttpExceptionFilter ( ) ) ;
59+
60+ const port = process . env . PORT || 3000 ;
61+ await app . listen ( port , '0.0.0.0' ) ; // Escuta em todas as interfaces
62+ console . log ( `✅ Aplicação rodando na porta ${ port } ` ) ;
7163}
7264
7365bootstrap ( ) ;
0 commit comments