Reputation: 2725
There is a nodejs (express) app. It has few router handlers. I want the app after getting SIGTERM to respond with 500 status to all the routes. How can I achieve that? I tried:
process.on('SIGTERM', () => {
console.log('SIGTERM CATCHED');
app.use((req, res) => {
console.log('RESPONDING PROPERLY')
res.sendStatus(500);
})
});
But that would definitely not override the more specific handlers. Additionally, I shouldn't shutdown the app.
Upvotes: 1
Views: 53
Reputation: 422
You can use a session variable that you set to 'true' once a SIGTERM is caught (catched if you want :) ). Then you define a middleware that tests if this session variable is false then next() else res.sendStatus(500).
Upvotes: 1