59 lines
1.6 KiB
TypeScript
59 lines
1.6 KiB
TypeScript
|
|
import { NestFactory } from '@nestjs/core';
|
||
|
|
import { ValidationPipe } from '@nestjs/common';
|
||
|
|
import { SwaggerModule, DocumentBuilder } from '@nestjs/swagger';
|
||
|
|
import { ConfigService } from '@nestjs/config';
|
||
|
|
import helmet from 'helmet';
|
||
|
|
import cookieParser from 'cookie-parser';
|
||
|
|
import { AppModule } from './app.module';
|
||
|
|
|
||
|
|
async function bootstrap() {
|
||
|
|
const app = await NestFactory.create(AppModule);
|
||
|
|
const configService = app.get(ConfigService);
|
||
|
|
|
||
|
|
// Security
|
||
|
|
app.use(helmet());
|
||
|
|
app.use(cookieParser());
|
||
|
|
|
||
|
|
// CORS
|
||
|
|
app.enableCors({
|
||
|
|
origin: configService.get('CORS_ORIGIN', 'http://localhost:3000'),
|
||
|
|
credentials: true,
|
||
|
|
});
|
||
|
|
|
||
|
|
// Global validation pipe
|
||
|
|
app.useGlobalPipes(
|
||
|
|
new ValidationPipe({
|
||
|
|
transform: true,
|
||
|
|
whitelist: true,
|
||
|
|
forbidNonWhitelisted: true,
|
||
|
|
}),
|
||
|
|
);
|
||
|
|
|
||
|
|
// Global prefix
|
||
|
|
app.setGlobalPrefix('api');
|
||
|
|
|
||
|
|
// Swagger documentation
|
||
|
|
if (configService.get('NODE_ENV') !== 'production') {
|
||
|
|
const config = new DocumentBuilder()
|
||
|
|
.setTitle('Customer Portal API')
|
||
|
|
.setDescription('Backend for Frontend API for customer portal')
|
||
|
|
.setVersion('1.0')
|
||
|
|
.addBearerAuth()
|
||
|
|
.addCookieAuth('auth-cookie')
|
||
|
|
.build();
|
||
|
|
|
||
|
|
const document = SwaggerModule.createDocument(app, config);
|
||
|
|
SwaggerModule.setup('api/docs', app, document);
|
||
|
|
}
|
||
|
|
|
||
|
|
const port = configService.get('PORT', 4000);
|
||
|
|
await app.listen(port);
|
||
|
|
|
||
|
|
console.log(`🚀 BFF API running on: http://localhost:${port}/api`);
|
||
|
|
if (configService.get('NODE_ENV') !== 'production') {
|
||
|
|
console.log(`📚 API Documentation: http://localhost:${port}/api/docs`);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
bootstrap();
|