2025-11-12 21:42:52 +01:00
|
|
|
require('dotenv').config();
|
|
|
|
|
const app = require('./app');
|
2025-11-12 21:56:11 +01:00
|
|
|
const { testConnection, disconnect } = require('./utils/db');
|
2025-11-12 21:42:52 +01:00
|
|
|
|
|
|
|
|
const PORT = process.env.PORT || 3000;
|
|
|
|
|
|
2025-11-12 21:56:11 +01:00
|
|
|
async function startServer() {
|
|
|
|
|
// Test database connection
|
|
|
|
|
await testConnection();
|
|
|
|
|
|
|
|
|
|
const server = app.listen(PORT, '0.0.0.0', () => {
|
|
|
|
|
console.log('=================================');
|
|
|
|
|
console.log('🚀 spotlight.cam Backend Started');
|
|
|
|
|
console.log('=================================');
|
|
|
|
|
console.log(`Environment: ${process.env.NODE_ENV || 'development'}`);
|
|
|
|
|
console.log(`Server running on port: ${PORT}`);
|
|
|
|
|
console.log(`Health check: http://localhost:${PORT}/api/health`);
|
|
|
|
|
console.log('=================================');
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return server;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
startServer().catch((err) => {
|
|
|
|
|
console.error('Failed to start server:', err);
|
|
|
|
|
process.exit(1);
|
2025-11-12 21:42:52 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// Graceful shutdown
|
2025-11-12 21:56:11 +01:00
|
|
|
process.on('SIGTERM', async () => {
|
2025-11-12 21:42:52 +01:00
|
|
|
console.log('SIGTERM received, shutting down gracefully...');
|
2025-11-12 21:56:11 +01:00
|
|
|
await disconnect();
|
|
|
|
|
process.exit(0);
|
2025-11-12 21:42:52 +01:00
|
|
|
});
|
|
|
|
|
|
2025-11-12 21:56:11 +01:00
|
|
|
process.on('SIGINT', async () => {
|
2025-11-12 21:42:52 +01:00
|
|
|
console.log('SIGINT received, shutting down gracefully...');
|
2025-11-12 21:56:11 +01:00
|
|
|
await disconnect();
|
|
|
|
|
process.exit(0);
|
2025-11-12 21:42:52 +01:00
|
|
|
});
|