diff --git a/backend/server.js b/backend/server.js index a13c427..29eeafd 100644 --- a/backend/server.js +++ b/backend/server.js @@ -4,6 +4,7 @@ const http = require('http'); const cors = require('cors'); const { bootstrapGames } = require('./bootstrap'); const { WebSocketManager, setWebSocketManager } = require('./utils/websocket-manager'); +const { cleanupAllShards } = require('./utils/ecast-shard-client'); const app = express(); const PORT = process.env.PORT || 5000; @@ -53,6 +54,15 @@ if (require.main === module) { console.log(`Server is running on port ${PORT}`); console.log(`WebSocket server available at ws://localhost:${PORT}/api/sessions/live`); }); + + const shutdown = async () => { + console.log('Shutting down gracefully...'); + await cleanupAllShards(); + server.close(() => process.exit(0)); + }; + + process.on('SIGTERM', shutdown); + process.on('SIGINT', shutdown); } module.exports = { app, server };