@godaddy/terminus
Advanced tools
Comparing version 4.2.1 to 4.3.0
@@ -28,3 +28,3 @@ const express = require('express') | ||
.then(() => { | ||
console.info(`Mongoose has disconnected`) | ||
console.info('Mongoose has disconnected') | ||
resolve() | ||
@@ -31,0 +31,0 @@ }) |
@@ -28,3 +28,3 @@ const Koa = require('koa') | ||
.then(() => { | ||
console.info(`Mongoose has disconnected`) | ||
console.info('Mongoose has disconnected') | ||
resolve() | ||
@@ -31,0 +31,0 @@ }) |
@@ -63,3 +63,3 @@ 'use strict' | ||
function decorateWithHealthCheck (server, state, options) { | ||
const { healthChecks, logger, onSendFailureDuringShutdown } = options | ||
const { healthChecks, logger, onSendFailureDuringShutdown, caseInsensitive } = options | ||
@@ -69,3 +69,5 @@ server.listeners('request').forEach((listener) => { | ||
server.on('request', async (req, res) => { | ||
if (healthChecks[req.url]) { | ||
const url = caseInsensitive ? req.url : req.url.toLowerCase() | ||
const healthCheck = healthChecks[url] | ||
if (healthCheck) { | ||
if (state.isShuttingDown) { | ||
@@ -76,3 +78,3 @@ return sendFailure(res, { onSendFailureDuringShutdown }) | ||
try { | ||
info = await healthChecks[req.url]() | ||
info = await healthCheck() | ||
} catch (error) { | ||
@@ -119,3 +121,15 @@ logger('healthcheck failed', error) | ||
function terminus (server, options = {}) { | ||
const { signal = 'SIGTERM', | ||
// Supporting case insensitive routes by lowering case all routes. | ||
if (options.caseInsensitive && options.healthChecks) { | ||
const healthChecks = {} | ||
for (const key in options.healthChecks) { | ||
healthChecks[key.toLowerCase()] = options.healthChecks[key] | ||
} | ||
options.healthChecks = healthChecks | ||
} | ||
const { | ||
signal = 'SIGTERM', | ||
signals = [], | ||
@@ -127,3 +141,5 @@ timeout = 1000, | ||
beforeShutdown = noopResolves, | ||
logger = noop } = options | ||
logger = noop, | ||
caseInsensitive = false | ||
} = options | ||
const onSignal = options.onSignal || options.onSigterm || noopResolves | ||
@@ -136,3 +152,4 @@ const state = Object.assign({}, intialState) | ||
logger, | ||
onSendFailureDuringShutdown | ||
onSendFailureDuringShutdown, | ||
caseInsensitive | ||
}) | ||
@@ -139,0 +156,0 @@ } |
@@ -52,2 +52,37 @@ 'use strict' | ||
it('case sensitive by default', async () => { | ||
let onHealthCheckRan = false | ||
createTerminus(server, { | ||
healthChecks: { | ||
'/HeAlTh': () => { | ||
onHealthCheckRan = true | ||
return Promise.resolve() | ||
} | ||
} | ||
}) | ||
server.listen(8000) | ||
await fetch('http://localhost:8000/health') | ||
expect(onHealthCheckRan).to.eql(false) | ||
}) | ||
it('case insensitive opt-in', async () => { | ||
let onHealthCheckRan = false | ||
createTerminus(server, { | ||
healthChecks: { | ||
'/HeAlTh': () => { | ||
onHealthCheckRan = true | ||
return Promise.resolve() | ||
} | ||
}, | ||
caseInsensitive: true | ||
}) | ||
server.listen(8000) | ||
await fetch('http://localhost:8000/health') | ||
expect(onHealthCheckRan).to.eql(true) | ||
}) | ||
it('includes info on resolve', async () => { | ||
@@ -54,0 +89,0 @@ let onHealthCheckRan = false |
{ | ||
"name": "@godaddy/terminus", | ||
"version": "4.2.1", | ||
"version": "4.3.0", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -60,2 +60,3 @@ | ||
}, | ||
caseInsensitive, // [optional] whether given health checks routes are case insensitive (defaults to false) | ||
@@ -62,0 +63,0 @@ // cleanup options |
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
43927
1080
181
33