backend: graceful shutdown in prod
This commit is contained in:
@@ -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);
|
||||||
Reference in New Issue
Block a user