INNER CODE UNIT · JavaScript
decorateWithHealthCheck
godaddy/terminus · lib/terminus.js:73
function decorateWithHealthCheck (server, state, options) {
const { healthChecks, logger, headers, onSendFailureDuringShutdown, sendFailuresDuringShutdown, caseInsensitive, statusOk, statusOkResponse, statusError, statusErrorResponse } = options
let hasSetHandler = false
const createHandler = (listener) => {
const check = hasSetHandler
? () => {}
: async (healthCheck, res) => {
if (state.isShuttingDown && sendFailuresDuringShutdown) {
return sendFailure(res, { onSendFailureDuringShutdown, statusError, statusErrorResponse })
}
let info
try {
info = await healthCheck({ state })
} catch (error) {
logger('healthcheck failed', error)
const statusCode = error.statusCode
const statusResponse = error.statusResponse