@spokedev/healthchicken
v0.0.9
Published
[![pipeline status](https://gitlab.spokedev.xyz/products/marketplace/healthchicken/badges/master/pipeline.svg)](https://gitlab.spokedev.xyz/products/marketplace/healthchicken/commits/master) [![coverage report](https://gitlab.spokedev.xyz/products/marketp
Downloads
5
Readme
healthchicken
Healthchicken is express middleware that binds routes to ${serviceName}/healthcheck/ping
and ${serviceName}/healthcheck/ready
. By default, if the app is healthy, these will always return 200
statuscodes and a {message: 'OK'}
json body. You can also specify dependent services. These will be pinged by the ready
route. If they are all good, the ready route will return a 200
else you are getting a 500
.
Install
$ npm i @spokedev/healthchicken
Usage
Basic usage
const healthchicken = require("healthchicken");
const express = require("express");
const app = express();
app.use(healthchicken({
serviceName: "cats_n_chickens"
}))
// we now have routes at `cats_n_chickens/healthcheck/ready` and `cats_n_chickens/healthcheck/ping`
Specifying dependent services
const healthchicken = require("healthchicken");
const express = require("express");
const app = express();
app.use(healthchicken({
serviceName: "cats_n_chickens",
dependentUrls: ["http://some-other.service"]
}))
// `cats_n_chickens/healthcheck/ready` will now ping `http://some-other.service/healthcheck/ping`
// and fail if it doesn't get a 2xx back.
Using a different prefix
const healthchicken = require("healthchicken");
const express = require("express");
const app = express();
app.use(healthchicken({
serviceName: "cats_n_chickens",
prefix: "deathwatch"
}))
// we now have routes at `cats_n_chickens/deathwatch/ready` and `cats_n_chickens/deathwatch/ping`
Adding in version
If the version is found as an environment variable as SERVICE_VERSION
then it will be output as part of the ready
healthcheck.