@godaddy/terminus
Advanced tools
Comparing version 4.8.0 to 4.9.0
@@ -18,4 +18,4 @@ 'use strict' | ||
async function sendSuccess (res, { info, verbatim }) { | ||
res.statusCode = 200 | ||
async function sendSuccess (res, { info, verbatim, statusOk }) { | ||
res.statusCode = statusOk | ||
res.setHeader('Content-Type', 'application/json') | ||
@@ -38,3 +38,3 @@ if (info) { | ||
async function sendFailure (res, options) { | ||
const { error, onSendFailureDuringShutdown, exposeStackTraces } = options | ||
const { error, onSendFailureDuringShutdown, exposeStackTraces, statusCode, statusError } = options | ||
@@ -59,3 +59,3 @@ function replaceErrors (_, value) { | ||
} | ||
res.statusCode = 503 | ||
res.statusCode = statusCode || statusError | ||
res.setHeader('Content-Type', 'application/json') | ||
@@ -79,3 +79,3 @@ if (error) { | ||
function decorateWithHealthCheck (server, state, options) { | ||
const { healthChecks, logger, onSendFailureDuringShutdown, sendFailuresDuringShutdown, caseInsensitive } = options | ||
const { healthChecks, logger, onSendFailureDuringShutdown, sendFailuresDuringShutdown, caseInsensitive, statusOk, statusError } = options | ||
@@ -88,3 +88,3 @@ let hasSetHandler = false | ||
if (state.isShuttingDown && sendFailuresDuringShutdown) { | ||
return sendFailure(res, { onSendFailureDuringShutdown }) | ||
return sendFailure(res, { onSendFailureDuringShutdown, statusError }) | ||
} | ||
@@ -96,5 +96,5 @@ let info | ||
logger('healthcheck failed', error) | ||
return sendFailure(res, { error: error.causes, exposeStackTraces: healthChecks.__unsafeExposeStackTraces }) | ||
return sendFailure(res, { error: error.causes, exposeStackTraces: healthChecks.__unsafeExposeStackTraces, statusCode: error.statusCode, statusError }) | ||
} | ||
return sendSuccess(res, { info, verbatim: healthChecks.verbatim }) | ||
return sendSuccess(res, { info, verbatim: healthChecks.verbatim, statusOk }) | ||
} | ||
@@ -171,3 +171,5 @@ | ||
logger = noop, | ||
caseInsensitive = false | ||
caseInsensitive = false, | ||
statusOk = 200, | ||
statusError = 503 | ||
} = options | ||
@@ -183,3 +185,5 @@ const onSignal = options.onSignal || options.onSigterm || noopResolves | ||
onSendFailureDuringShutdown, | ||
caseInsensitive | ||
caseInsensitive, | ||
statusOk, | ||
statusError | ||
}) | ||
@@ -186,0 +190,0 @@ } |
{ | ||
"name": "@godaddy/terminus", | ||
"version": "4.8.0", | ||
"version": "4.9.0", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -55,19 +55,22 @@ # terminus | ||
'/healthcheck': healthCheck, // a function accepting a state and returning a promise indicating service health, | ||
verbatim: true, // [optional = false] use object returned from /healthcheck verbatim in response, | ||
verbatim: true, // [optional = false] use object returned from /healthcheck verbatim in response, | ||
__unsafeExposeStackTraces: true // [optional = false] return stack traces in error response if healthchecks throw errors | ||
}, | ||
caseInsensitive, // [optional] whether given health checks routes are case insensitive (defaults to false) | ||
caseInsensitive, // [optional] whether given health checks routes are case insensitive (defaults to false) | ||
statusOk, // [optional = 200] status to be returned for successful healthchecks | ||
statusError, // [optional = 503] status to be returned for unsuccessful healthchecks | ||
// cleanup options | ||
timeout: 1000, // [optional = 1000] number of milliseconds before forceful exiting | ||
signal, // [optional = 'SIGTERM'] what signal to listen for relative to shutdown | ||
signals, // [optional = []] array of signals to listen for relative to shutdown | ||
sendFailuresDuringShutdown, // [optional = true] whether or not to send failure (503) during shutdown | ||
beforeShutdown, // [optional] called before the HTTP server starts its shutdown | ||
onSignal, // [optional] cleanup function, returning a promise (used to be onSigterm) | ||
onShutdown, // [optional] called right before exiting | ||
onSendFailureDuringShutdown, // [optional] called before sending each 503 during shutdowns | ||
timeout: 1000, // [optional = 1000] number of milliseconds before forceful exiting | ||
signal, // [optional = 'SIGTERM'] what signal to listen for relative to shutdown | ||
signals, // [optional = []] array of signals to listen for relative to shutdown | ||
sendFailuresDuringShutdown, // [optional = true] whether or not to send failure (503) during shutdown | ||
beforeShutdown, // [optional] called before the HTTP server starts its shutdown | ||
onSignal, // [optional] cleanup function, returning a promise (used to be onSigterm) | ||
onShutdown, // [optional] called right before exiting | ||
onSendFailureDuringShutdown, // [optional] called before sending each 503 during shutdowns | ||
// both | ||
logger // [optional] logger function to be called with errors. Example logger call: ('error happened during shutdown', error). See terminus.js for more details. | ||
logger // [optional] logger function to be called with errors. Example logger call: ('error happened during shutdown', error). See terminus.js for more details. | ||
}; | ||
@@ -74,0 +77,0 @@ |
@@ -22,2 +22,4 @@ declare module "@godaddy/terminus" { | ||
sendFailuresDuringShutdown?: boolean; | ||
statusOk?: number, | ||
statusError?: number, | ||
onSignal?: () => Promise<any>; | ||
@@ -24,0 +26,0 @@ onSendFailureDuringShutdown?: () => Promise<any>; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
27182
535
183