Skip to content

Supercharge your AI agents with data from the web and beyond. Building the library for superintelligence. 🔥

feat(api): graceful shutdown for less 502 errors

Gergő Móricz740a429790c2
diff --git a/apps/api/src/index.ts b/apps/api/src/index.ts
index 7f7ec036c..049b37a95 100644
--- a/apps/api/src/index.ts
+++ b/apps/api/src/index.ts
@@ -80,6 +80,17 @@ function startServer(port = DEFAULT_PORT) {
`For the Queue UI, open: http://${HOST}:${port}/admin/${process.env.BULL_AUTH_KEY}/queues`
);
});
+
+ const exitHandler = () => {
+ logger.info('SIGTERM signal received: closing HTTP server')
+ server.close(() => {
+ logger.info("Server closed.");
+ process.exit(0);
+ });
+ };
+
+ process.on('SIGTERM', exitHandler);
+ process.on('SIGINT', exitHandler);
return server;
}