diff --git a/src/server.js b/src/server.js index 0850e5f20..65e8b2c29 100644 --- a/src/server.js +++ b/src/server.js @@ -590,6 +590,16 @@ function start(opts) { }; } +/** + * Stop the server gracefully + * + * @param {string} signal Name of the received signal + */ +function stopGracefully(signal) { + console.log(`Caught signal ${signal}, stopping gracefully`); + process.exit(); +} + /** * * @param opts @@ -602,11 +612,11 @@ export function server(opts) { process.exit(1); }); - process.on('SIGINT', () => { - process.exit(); - }); + process.on('SIGINT', stopGracefully); + process.on('SIGTERM', stopGracefully); - process.on('SIGHUP', () => { + process.on('SIGHUP', (signal) => { + console.log(`Caught signal ${signal}, refreshing`); console.log('Stopping server and reloading config'); running.server.shutdown(() => { diff --git a/src/utils.js b/src/utils.js index bc275402f..c9bc46628 100644 --- a/src/utils.js +++ b/src/utils.js @@ -8,9 +8,11 @@ import glyphCompose from '@mapbox/glyph-pbf-composite'; /** * Generate new URL object + * + * @param req * @params {object} req - Express request * @returns {URL} object - **/ + */ const getUrlObject = (req) => { const urlObject = new URL(`${req.protocol}://${req.headers.host}/`); // support overriding hostname by sending X-Forwarded-Host http header