keystone-healthchecks
Healthchecks Framework for KeystoneJS (or any Express app)
Enable the default healthchecks for Keystone by adding this package to your project and setting the following option:
keystone
Or, you can define your own healthchecks and import them like this:
// this will import all javascript files in the ./healthchecks directorykeystone;
Custom Integration
For more control, you can create the healthcheck route handler and plug it into
any express app or router by using the createRoute
method, e.g
const checks = MyHealthCheck ; // see belowapp;
Creating Healthchecks
Each healthcheck should export a Class that extends Healthcheck
, e.g
const healthchecks = ;const Healthcheck = healthchecksHealthcheck; moduleexports = // optional, will default to the name of the Class { return `My Health Check`; } // optional, defines a timeout for the check in ms { return 500; } // required, must return a Promise or Promise.resolve for pass or // Promise.reject for fail. The argument passed to the resolve / reject // will be returned by the healthcheck endpoint, along with the status { return ; };
Using Existing Health Checks
There are several health checks of kinds often used in a keystone application provided, a List health check to check on a keystone model and ensure database connectivity, and a uri health check that can check a generic external dependency.
These both have a class that extends HealthCheck
as well as a factory function to create them.
These can be required at:
const healthchecks = ;
canQueryListFactory
This function takes in a keystone List object, and returns a health check that will perform a findOne
operation on the list. You can set one up as follows:
const User = ;const canQueryListFactory = healthcheckscanQueryListFactory const check = ;
canQueryUriFactory
This is a standard health check for an external uri which does not require any form of authorisation. It makes a http request to the endpoint, and treats a 200 response as a valid status, while treating all other responses as an error. It can be set up as follows.
It has one required parameters, a uri
, and then two optional parameters, siteName
and timeout
.
If no siteName
is provided, the check's name is defaulted to the uri. If no timeout
is provided, the timeout
is defaulted to 3 seconds.
const canQueryUriFactory = healthcheckscanQueryUriFactory const check =
License
MIT Licensed. Copyright (c) 2017 Thinkmill Pty Ltd