handle SIGTERM gracefully in unfurler

This commit is contained in:
Mononaut committed 2022-08-11 17:43:26 +00:00
1 parent e4342113fa
commit 06f232fdd8
1 file changed
+16
+16
View File
@@ -48,6 +48,16 @@ class Server {
});
}
async stopServer() {
if (this.cluster) {
await this.cluster.idle();
await this.cluster.close();
}
if (this.server) {
await this.server.close();
}
}
setUpRoutes() {
this.app.get('/render*', async (req, res) => { return this.renderPreview(req, res) })
this.app.get('*', (req, res) => { return this.renderHTML(req, res) })
@@ -133,3 +143,9 @@ class Server {
}
const server = new Server();
process.on('SIGTERM', async () => {
console.info('Shutting down Mempool Unfurl Server');
await server.stopServer();
process.exit(0);
});