const http = require('http'); const app = require('./app'); const port = parseInt(process.env.PORT, 10) || 3000; const server = http.createServer(app); 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'); } }); 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;