2025-03-26 14:39:56 -06:00
import { NestFactory } from '@nestjs/core' ;
import { AppModule } from './app.module' ;
2025-04-02 11:50:08 -06:00
import { ValidationPipe } from '@nestjs/common' ;
2025-06-13 22:41:20 -06:00
import { ConfigService } from '@nestjs/config' ;
import { DocumentBuilder , SwaggerModule } from '@nestjs/swagger' ;
2025-06-16 13:49:12 -06:00
import { NestExpressApplication } from '@nestjs/platform-express' ;
import { join } from 'path' ;
2025-03-26 14:39:56 -06:00
async function bootstrap() {
2025-06-16 13:49:12 -06:00
const app = await NestFactory . create < NestExpressApplication >( AppModule );
2025-06-13 22:41:20 -06:00
const configService = app . get ( ConfigService );
2025-04-02 11:50:08 -06:00
// Configuración de validación global
app . useGlobalPipes (
new ValidationPipe ({
whitelist : true , // Elimina propiedades no decoradas
transform : true , // Transforma los datos recibidos al tipo definido en el DTO
2025-06-13 22:41:20 -06:00
}),
2025-04-02 11:50:08 -06:00
);
2025-06-13 22:41:20 -06:00
2025-06-16 13:49:12 -06:00
app . useStaticAssets ( join ( __dirname , '..' , 'uploads' ), {
index : false ,
prefix : '/' ,
});
2025-04-02 11:50:08 -06:00
// CORS configuration
app . enableCors ({
origin : '*' ,
methods : [ 'GET' , 'POST' , 'PUT' , 'DELETE' , 'PATCH' ],
allowedHeaders : [ 'Content-Type' , 'Authorization' ],
});
2025-04-02 09:15:14 -06:00
2025-06-13 22:41:20 -06:00
const config = new DocumentBuilder ()
. setTitle ( 'Formularios API' )
. setDescription (
`Esta es la API del sistema de registros para eventos de la FES Acatlán. Permite gestionar eventos académicos y sus formularios asociados.
Flujo de creación:
1. Primero, se debe crear un evento usando **POST /evento**.
2. Luego, se crea un formulario y se relaciona con el evento usando **POST /cuestionario**.
3. (Opcional) También se puede crear un formulario y un evento al mismo tiempo usando **POST /cuestionario/evento**, lo cual genera automáticamente ambos y los relaciona.` ,
)
. setVersion ( '1.0' )
. addBearerAuth ()
. addTag ( 'Evento' )
. addTag ( 'Cuestionario' )
. addTag ( 'Cuestionario Respondido' )
. build ();
const document = SwaggerModule . createDocument ( app , config );
SwaggerModule . setup ( 'api-docs' , app , document );
2025-04-02 11:50:08 -06:00
// Start the server
2025-06-13 22:41:20 -06:00
await app . listen ( configService . get < number >( 'API_PORT' ) || 4200 );
console . log ( '\nAPI en ejecución en http://localhost:4200' );
2025-04-02 12:43:37 -06:00
console . log ( 'Swagger disponible en http://localhost:4200/api-docs' );
2025-03-26 14:39:56 -06:00
}
bootstrap ();