@shortlyster/its-alive
Advanced tools
Comparing version 1.0.3 to 1.0.4
@@ -1,3 +0,5 @@ | ||
/// <reference types="express" /> | ||
import { Router } from 'express'; | ||
/// <reference types="node" /> | ||
import { IncomingMessage, ServerResponse } from 'http'; | ||
export declare type Next = (error?: Error) => void; | ||
export declare type Middleware = (req: IncomingMessage, res: ServerResponse, next: Next) => void; | ||
export interface IOptions { | ||
@@ -7,2 +9,2 @@ readyWhen?: () => boolean | Promise<boolean>; | ||
} | ||
export default function (options?: IOptions): Router; | ||
export default function (options?: IOptions): Middleware; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const express_1 = require("express"); | ||
const noop = () => true; | ||
const sendResponse = (okay, res) => { | ||
const status = okay ? 200 : 503; | ||
const payload = okay ? 'OK' : 'NOPE'; | ||
res.status(status).send(payload); | ||
res.setHeader('Content-Length', payload.length); | ||
res.setHeader('Content-Type', 'text/plain'); | ||
res.statusCode = okay ? 200 : 503; | ||
res.end(payload); | ||
}; | ||
function default_1(options = {}) { | ||
const { readyWhen = noop, aliveWhen = noop } = options; | ||
return express_1.Router() | ||
.get('/_health/ready', async (_, res) => { | ||
const itsReady = await Promise.resolve(readyWhen()); | ||
sendResponse(itsReady, res); | ||
}) | ||
.get('/_health/alive', async (_, res) => { | ||
const itsAlive = await Promise.resolve(aliveWhen()); | ||
sendResponse(itsAlive, res); | ||
}); | ||
return (req, res, next) => { | ||
if (req.url === '/_health/ready') { | ||
Promise.resolve(readyWhen()).then(isReady => sendResponse(isReady, res)).catch(next); | ||
} | ||
else if (req.url === '/_health/alive') { | ||
Promise.resolve(aliveWhen()).then(isReady => sendResponse(isReady, res)).catch(next); | ||
} | ||
else { | ||
next(); | ||
} | ||
}; | ||
} | ||
exports.default = default_1; |
{ | ||
"name": "@shortlyster/its-alive", | ||
"version": "1.0.3", | ||
"version": "1.0.4", | ||
"description": "livechecks middleware", | ||
@@ -33,10 +33,8 @@ "files": [ | ||
"homepage": "https://github.com/MadRabbit/its-alive#readme", | ||
"peerDependencies": { | ||
"express": "^4.16.2" | ||
}, | ||
"devDependencies": { | ||
"@types/express": "^4.0.39", | ||
"@types/jest": "^21.1.8", | ||
"@types/node": "^8.5.2", | ||
"doubleagent": "^1.1.1", | ||
"express": "^4.16.2", | ||
"doubleagent": "^1.1.0", | ||
"husky": "^0.14.3", | ||
@@ -43,0 +41,0 @@ "jest": "^21.2.1", |
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
3480
0
34
11