hapi-health-check
v1.1.0
Published
Add new route that can be used as a heath check for the application and the backends
Downloads
1
Readme
= hapi-health-check
A https://github.com/hapijs/hapi[hapi] plugin used to add a health check to a server.
Internally it is using the library https://github.com/atomantic/hapi-and-healthy[hapi-and-healthy].
== Requirements
- nodejs >= 4
- npm >= 2
== Install
[source,shell] .Add the dependency to your package.json
npm install hapi-health-check --save
== Usage === Importing the lib
[source,javascript] .Require the lib if using ES5
var hapiHealthCheck = require('hapi-health-check');
[source,javascript] .Import the module if using ES6
import hapiHealthCheck from 'hapi-health-check'
=== Using the lib
[source,javascript] .Register the plugin in your Hapi server (ES6 syntax)
import hapiHealthcheck from 'hapi-health-check'
Server.register({ register: hapiHealthcheck, // options are explained below. Options are not mandatory. Default values are the one used in this snippet. options: { path: '/status', health_checks: [{}], custom_health_checks: [], feature_health_checks: [{}], custom_feature_health_checks: [], } }, (err) => { // handle error })
[source,javascript] .Use built-in healthchecks
Server.register({ register: hapiHealthcheck, options: { path: '/status', // you can choose among all these built-in health checks health_checks: [ { type: 'postgres', options: { url: 'POSTGRES_URL', ssl: false // default value }, { type: 'redis', options: { url: 'REDIS_URL' }, { type: 's3', options: { access_key_id: 'ACCESS_KEY_ID', secret_access_key: 'SECRET_ACCESS_KEY' }, { type: 'nats', options: { url: 'NATS_URL' } ] } })
Other options are the following :
custom_health_checks
: an array of functions doing custom health checks.feature_health_checks
: same type of array ashealth_checks
but if one of theses checks fail, the plugin will not return a failure but a warning.custom_feature_health_checks
: an array of functions doing custom health checks. If one of theses health checks fails, the plugin will not return a failure but a warning.
For others use cases, you can look at the tests in the test
directory.
== Run tests
To run the tests, you must define some environment variables to execute the tests (or put them in a .env
file at the root of this project):
DATABASE_URL
: url the Postgres databaseREDIS_URL
: url of RedisNATS_URL
: url of natsACCESS_KEY_ID
: access key to Amazon S3SECRET_ACCESS_KEY
: secret access key to amazon S3
[source,shell] .Execute the tests
npm test
== Licence
link:LICENCE[MIT]