49 lines
1.5 KiB
TypeScript
49 lines
1.5 KiB
TypeScript
import { NestFactory } from '@nestjs/core';
|
|
import { ValidationPipe } from '@nestjs/common';
|
|
import { DocumentBuilder, SwaggerModule } from '@nestjs/swagger';
|
|
import * as helmet from 'helmet';
|
|
import compression = require('compression');
|
|
import { AppModule } from './app.module';
|
|
|
|
async function bootstrap() {
|
|
const app = await NestFactory.create(AppModule);
|
|
|
|
app.setGlobalPrefix('api/v1');
|
|
|
|
app.enableCors({ origin: '*' });
|
|
|
|
app.use(helmet.default());
|
|
app.use(compression());
|
|
|
|
app.useGlobalPipes(
|
|
new ValidationPipe({
|
|
whitelist: true,
|
|
forbidNonWhitelisted: false,
|
|
transform: true,
|
|
transformOptions: { enableImplicitConversion: true },
|
|
}),
|
|
);
|
|
|
|
const config = new DocumentBuilder()
|
|
.setTitle('API Ubigeo Peru')
|
|
.setDescription(
|
|
'API de ubicaciones geográficas del Perú (departamentos, provincias, distritos) y países del mundo. Fuente: INEI 2025.',
|
|
)
|
|
.setVersion('1.0')
|
|
.addTag('ubigeo', 'Departamentos, provincias y distritos del Perú')
|
|
.addTag('paises', 'Países del mundo')
|
|
.addTag('health', 'Estado del servicio')
|
|
.build();
|
|
|
|
const document = SwaggerModule.createDocument(app, config);
|
|
SwaggerModule.setup('api/docs', app, document, {
|
|
swaggerOptions: { persistAuthorization: true },
|
|
});
|
|
|
|
const port = process.env.PORT ?? 3200;
|
|
await app.listen(port);
|
|
console.log(`API Ubigeo corriendo en: http://localhost:${port}/api/v1`);
|
|
console.log(`Swagger docs: http://localhost:${port}/api/docs`);
|
|
}
|
|
bootstrap();
|