backend: graceful shutdown in prod

This commit is contained in:
2025-02-15 16:45:59 -08:00
parent 79f53bbffe
commit 9a8f7b9ac5

View File

@@ -106,6 +106,27 @@ app.get("*", (req, res) => {
res.sendFile("dist/frontend/index.html", { root: "." }); res.sendFile("dist/frontend/index.html", { root: "." });
}); });
app.listen(3000, () => { const port = process.env.PORT || 3000;
console.log("Server is running on port 3000"); const server = app.listen(port, () => {
}); console.log(`Server is running on port ${port}`);
});
// Add graceful shutdown handling
const shutdown = async () => {
console.log('Received shutdown signal. Closing server...');
server.close(() => {
console.log('Server closed');
process.exit(0);
});
// Force termination after some timeout (10sec)
setTimeout(() => {
console.log('Forcing server shutdown');
process.exit(1);
}, 10000);
};
// Handle various shutdown signals
process.on('SIGTERM', shutdown);
process.on('SIGINT', shutdown);