2025-12-30 09:16:07 -03:00
|
|
|
const http = require('http');
|
|
|
|
|
const app = require('./app');
|
2025-10-15 15:07:36 -03:00
|
|
|
|
2025-12-30 09:16:07 -03:00
|
|
|
const port = parseInt(process.env.PORT, 10) || 3000;
|
|
|
|
|
const server = http.createServer(app);
|
2025-10-15 15:07:36 -03:00
|
|
|
|
2025-12-30 09:16:07 -03:00
|
|
|
server.listen(port, () => {
|
|
|
|
|
console.log(`Server listening on port ${port} (env=${process.env.NODE_ENV || 'production'})`);
|
|
|
|
|
if (process.env.NODE_ENV === 'development' && process.env.DEV_SKIP_AUTH === 'true') {
|
|
|
|
|
console.log('[START-NOAUTH] DEV_SKIP_AUTH=true — authentication is bypassed');
|
|
|
|
|
}
|
2025-10-20 11:10:27 -03:00
|
|
|
});
|
|
|
|
|
|
2025-12-30 09:16:07 -03:00
|
|
|
function shutdown(signal) {
|
|
|
|
|
console.log(`Received ${signal}, shutting down...`);
|
|
|
|
|
server.close(() => {
|
|
|
|
|
console.log('Server closed.');
|
|
|
|
|
process.exit(0);
|
|
|
|
|
});
|
|
|
|
|
// force exit after 10s
|
|
|
|
|
setTimeout(() => {
|
|
|
|
|
console.error('Forcing shutdown.');
|
|
|
|
|
process.exit(1);
|
|
|
|
|
}, 10000).unref();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
process.on('SIGINT', () => shutdown('SIGINT'));
|
|
|
|
|
process.on('SIGTERM', () => shutdown('SIGTERM'));
|
|
|
|
|
|
|
|
|
|
// export for tests / scripts
|
|
|
|
|
module.exports = server;
|