-
Notifications
You must be signed in to change notification settings - Fork 96
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(status): Custom status response (#192)
* Added statusOkResponse to configuration The new configuration property: statusOkResponse will allow to globally configure the HTTP response body, used to respond with on a successful healthcheck. * Memoize the value of statusOkResponse When no healthtchecks were defined, the value of statusOkResponse would be returned as is. Therefore, memoizing its string representation would boost performance. * Added statusErrorResponse to configuration The new configuration property: statusErrorResponse will allow to globally configure the HTTP response body, used to respond with on an unsuccessful healthcheck. An unsuccessful healthcheck may override the global statusErrorResponse property by setting the statusResponse property on the Error object. * Incorporated use of headers
- Loading branch information
1 parent
c02925b
commit f61009a
Showing
6 changed files
with
464 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
lib/standalone-tests/terminus.onsignal.fail.custom.response.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
'use strict' | ||
const http = require('http') | ||
const server = http.createServer((req, res) => res.end('hello')) | ||
|
||
const { createTerminus } = require('../../') | ||
const SIGNAL = 'SIGINT' | ||
|
||
createTerminus(server, { | ||
healthChecks: { | ||
'/health': () => Promise.resolve() | ||
}, | ||
signal: SIGNAL, | ||
beforeShutdown: () => { | ||
return new Promise((resolve) => { | ||
setTimeout(resolve, 1000) | ||
}) | ||
}, | ||
statusErrorResponse: { status: 'down' } | ||
}) | ||
|
||
server.listen(8000, () => { | ||
process.kill(process.pid, SIGNAL) | ||
}) |
23 changes: 23 additions & 0 deletions
23
lib/standalone-tests/terminus.onsignal.fail.custom.status.code.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
'use strict' | ||
const http = require('http') | ||
const server = http.createServer((req, res) => res.end('hello')) | ||
|
||
const { createTerminus } = require('../../') | ||
const SIGNAL = 'SIGINT' | ||
|
||
createTerminus(server, { | ||
healthChecks: { | ||
'/health': () => Promise.resolve() | ||
}, | ||
signal: SIGNAL, | ||
beforeShutdown: () => { | ||
return new Promise((resolve) => { | ||
setTimeout(resolve, 1000) | ||
}) | ||
}, | ||
statusError: 501 | ||
}) | ||
|
||
server.listen(8000, () => { | ||
process.kill(process.pid, SIGNAL) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.