(server, options = {})
| 162 | } |
| 163 | |
| 164 | function terminus (server, options = {}) { |
| 165 | // Supporting case insensitive routes by lowering case all routes. |
| 166 | if (options.caseInsensitive && options.healthChecks) { |
| 167 | const healthChecks = {} |
| 168 | |
| 169 | for (const key in options.healthChecks) { |
| 170 | healthChecks[key.toLowerCase()] = options.healthChecks[key] |
| 171 | } |
| 172 | |
| 173 | options.healthChecks = healthChecks |
| 174 | } |
| 175 | |
| 176 | const { |
| 177 | signal = 'SIGTERM', |
| 178 | signals = [], |
| 179 | useExit0 = false, |
| 180 | timeout = 1000, |
| 181 | healthChecks = {}, |
| 182 | sendFailuresDuringShutdown = true, |
| 183 | onSendFailureDuringShutdown, |
| 184 | onShutdown = noopResolves, |
| 185 | beforeShutdown = noopResolves, |
| 186 | logger = noop, |
| 187 | caseInsensitive = false, |
| 188 | statusOk = 200, |
| 189 | statusOkResponse = { status: 'ok' }, |
| 190 | statusError = 503, |
| 191 | statusErrorResponse = { status: 'error' }, |
| 192 | headers = options.headers || {} |
| 193 | } = options |
| 194 | const onSignal = options.onSignal || options.onSigterm || noopResolves |
| 195 | const state = Object.assign({}, intialState) |
| 196 | |
| 197 | SUCCESS_RESPONSE = JSON.stringify(statusOkResponse) |
| 198 | |
| 199 | FAILURE_RESPONSE = JSON.stringify(statusErrorResponse) |
| 200 | |
| 201 | if (Object.keys(healthChecks).length > 0) { |
| 202 | decorateWithHealthCheck(server, state, { |
| 203 | healthChecks, |
| 204 | logger, |
| 205 | sendFailuresDuringShutdown, |
| 206 | onSendFailureDuringShutdown, |
| 207 | caseInsensitive, |
| 208 | statusOk, |
| 209 | statusOkResponse, |
| 210 | statusError, |
| 211 | statusErrorResponse, |
| 212 | headers |
| 213 | }) |
| 214 | } |
| 215 | |
| 216 | // push the signal into the array |
| 217 | // for backwards compatability |
| 218 | if (!signals.includes(signal)) signals.push(signal) |
| 219 | decorateWithSignalHandler(server, state, { |
| 220 | signals, |
| 221 | useExit0, |
no test coverage detected
searching dependent graphs…