import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
import { ValidationPipe } from '@nestjs/common';
import { GlobalExceptionFilter } from './global-exception.filter';
import { RequestLoggerInterceptor } from './request-logger.interceptor';

async function bootstrap() {
  const app = await NestFactory.create(AppModule);
  // app.enableCors(); // Enable CORS for all origins
  app.enableCors({
  origin: ['https://crm.ignosimoney.in', 'http://localhost:3001', 'http://localhost:3005'],
  methods: 'GET,HEAD,PUT,PATCH,POST,DELETE,OPTIONS',
  credentials: true,
});
  app.useGlobalPipes(new ValidationPipe({ transform: true }));
  app.useGlobalFilters(new GlobalExceptionFilter());
  app.useGlobalInterceptors(new RequestLoggerInterceptor());
  // Enable graceful shutdown so Prisma can properly disconnect on restart/stop
  app.enableShutdownHooks();
  await app.listen(process.env.PORT ?? 3004, '0.0.0.0');
}
bootstrap();
