Wipe up spilled milk in Hapi.
Plugin is a registrable replacement to Hapi.js' domain/protect logic which will gracefully shutdown Node as a result of a uncaught exception.
Plugin will return a 500
status code for the request which spawned the unhandled exception and 503
to any incoming requests until completely shut down.
shutdownHeaders
- Response headers to return when an error occurs. Defaults to{}
.responseHeaders
- Response headers to return post error, while the server is still shutting down. Defaults to{}
.shutdownTimeout
- Timeout option for Hapi.Server#stop. Defaults to10000
.lastly
- A final callback for clean up. Accepted signature:function(error)
. Called after server shutdown.
- Set the Hapi.Server.useDomains option to
false
. - Register the plugin.
const Hapi = require('hapi');
const server = new Hapi.Server({
useDomains: false
});
server.register({
register: require('sopalin'),
options: {
shutdownTimeout: 15000
}
}, (error) => {
server.route({
method: 'GET',
path: '/',
handler: function (request, reply) {
setImmediate(() => {
throw new Error('Something blew up!');
});
}
});
});