50 lines
1.4 KiB
TypeScript
50 lines
1.4 KiB
TypeScript
import { NestFactory } from '@nestjs/core';
|
|
import { NestExpressApplication } from '@nestjs/platform-express';
|
|
import { AppModule } from './app.module';
|
|
import { join } from 'path';
|
|
import { ValidationPipe } from '@nestjs/common';
|
|
import { SwaggerModule, DocumentBuilder } from '@nestjs/swagger';
|
|
import { HttpExceptionFilter } from './common/filters/http-exception.filter';
|
|
import helmet from 'helmet';
|
|
|
|
async function bootstrap() {
|
|
const app = await NestFactory.create<NestExpressApplication>(AppModule);
|
|
|
|
// Serve static uploads folder
|
|
app.useStaticAssets(join(process.cwd(), 'uploads'), {
|
|
prefix: '/uploads/',
|
|
});
|
|
|
|
app.use(helmet({
|
|
contentSecurityPolicy: false, // Avoid blocking Swagger UI scripts and assets
|
|
}));
|
|
|
|
app.setGlobalPrefix('api');
|
|
|
|
app.enableCors({
|
|
origin: true,
|
|
credentials: true,
|
|
});
|
|
|
|
app.useGlobalPipes(new ValidationPipe({
|
|
transform: true,
|
|
whitelist: true,
|
|
forbidNonWhitelisted: true,
|
|
}));
|
|
app.useGlobalFilters(new HttpExceptionFilter());
|
|
|
|
const config = new DocumentBuilder()
|
|
.setTitle('Canina Iran API')
|
|
.setDescription('API Documentation for Canina Iran Pet Health & Supplement Platform')
|
|
.setVersion('1.0.0')
|
|
.addBearerAuth()
|
|
.build();
|
|
|
|
const document = SwaggerModule.createDocument(app, config);
|
|
SwaggerModule.setup('api/docs', app, document);
|
|
|
|
await app.listen(process.env.PORT ?? 4001);
|
|
}
|
|
bootstrap();
|
|
|