import app from './app';
import config from './config';

const server = app.listen(config.port, config.host, () => {
  console.log(`🚀 API Gateway running on http://${config.host}:${config.port}`);
  console.log(`📊 Environment: ${config.nodeEnv}`);
  console.log(`🔒 CORS Origins: ${config.corsOrigins.join(', ')}`);
});

// Graceful shutdown
process.on('SIGTERM', () => {
  console.log('SIGTERM received, shutting down gracefully');
  server.close(() => {
    console.log('Process terminated');
    process.exit(0);
  });
});

process.on('SIGINT', () => {
  console.log('SIGINT received, shutting down gracefully');
  server.close(() => {
    console.log('Process terminated');
    process.exit(0);
  });
});

export default server;