@godaddy/terminus
Advanced tools
Comparing version 4.9.0 to 4.10.0
@@ -18,5 +18,5 @@ 'use strict' | ||
async function sendSuccess (res, { info, verbatim, statusOk }) { | ||
res.statusCode = statusOk | ||
async function sendSuccess (res, { info, verbatim, statusOk, headers }) { | ||
res.setHeader('Content-Type', 'application/json') | ||
res.writeHead(statusOk, headers) | ||
if (info) { | ||
@@ -38,3 +38,3 @@ return res.end( | ||
async function sendFailure (res, options) { | ||
const { error, onSendFailureDuringShutdown, exposeStackTraces, statusCode, statusError } = options | ||
const { error, headers, onSendFailureDuringShutdown, exposeStackTraces, statusCode, statusError } = options | ||
@@ -59,4 +59,4 @@ function replaceErrors (_, value) { | ||
} | ||
res.statusCode = statusCode || statusError | ||
res.setHeader('Content-Type', 'application/json') | ||
res.writeHead(statusCode || statusError, headers) | ||
if (error) { | ||
@@ -79,3 +79,3 @@ return res.end(JSON.stringify({ | ||
function decorateWithHealthCheck (server, state, options) { | ||
const { healthChecks, logger, onSendFailureDuringShutdown, sendFailuresDuringShutdown, caseInsensitive, statusOk, statusError } = options | ||
const { healthChecks, logger, headers, onSendFailureDuringShutdown, sendFailuresDuringShutdown, caseInsensitive, statusOk, statusError } = options | ||
@@ -95,5 +95,17 @@ let hasSetHandler = false | ||
logger('healthcheck failed', error) | ||
return sendFailure(res, { error: error.causes, exposeStackTraces: healthChecks.__unsafeExposeStackTraces, statusCode: error.statusCode, statusError }) | ||
return sendFailure( | ||
res, | ||
{ | ||
error: error.causes, | ||
headers, | ||
exposeStackTraces: healthChecks.__unsafeExposeStackTraces, | ||
statusCode: error.statusCode, | ||
statusError | ||
} | ||
) | ||
} | ||
return sendSuccess(res, { info, verbatim: healthChecks.verbatim, statusOk }) | ||
return sendSuccess( | ||
res, | ||
{ info, verbatim: healthChecks.verbatim, statusOk, headers } | ||
) | ||
} | ||
@@ -106,2 +118,3 @@ | ||
const healthCheck = healthChecks[url] | ||
if (healthCheck) { | ||
@@ -173,3 +186,4 @@ return check(healthCheck, res) | ||
statusOk = 200, | ||
statusError = 503 | ||
statusError = 503, | ||
headers = options.headers || {} | ||
} = options | ||
@@ -187,3 +201,4 @@ const onSignal = options.onSignal || options.onSigterm || noopResolves | ||
statusOk, | ||
statusError | ||
statusError, | ||
headers | ||
}) | ||
@@ -201,3 +216,4 @@ } | ||
timeout, | ||
logger | ||
logger, | ||
headers | ||
}) | ||
@@ -204,0 +220,0 @@ |
{ | ||
"name": "@godaddy/terminus", | ||
"version": "4.9.0", | ||
"version": "4.10.0", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -108,2 +108,36 @@ # terminus | ||
### With custom headers | ||
```js | ||
const http = require("http"); | ||
const express = require("express"); | ||
const { createTerminus, HealthCheckError } = require('@godaddy/terminus'); | ||
const app = express(); | ||
app.get("/", (req, res) => { | ||
res.send("ok"); | ||
}); | ||
const server = http.createServer(app); | ||
function healthCheck({ state }) { | ||
return Promise.resolve(); | ||
} | ||
const options = { | ||
healthChecks: { | ||
"/healthcheck": healthCheck, | ||
verbatim: true, | ||
__unsafeExposeStackTraces: true, | ||
}, | ||
headers: { | ||
"Access-Control-Allow-Origin": "*", | ||
"Access-Control-Allow-Methods": "OPTIONS, POST, GET", | ||
}, | ||
}; | ||
terminus.createTerminus(server, options); | ||
server.listen(3000); | ||
``` | ||
### With express | ||
@@ -110,0 +144,0 @@ |
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
28128
550
217