JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 2042
  • Score
    100M100P100Q113406F
  • License MIT

Health route for your Hapi.js server

Package Exports

  • hapi-alive

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (hapi-alive) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

hapi-alive

Build Status Code Climate Test Coverage

Health route for your Hapi.js server

Usage

Install from NPM

npm install --save hapi-alive

Example

var Hapi = require('hapi');

var server = new Hapi.Server();
server.connection({ port: 3000 });
// Register alive plugin
server.register({
    register: require('hapi-alive'),
    options: {
        path: '/health' //Health route path
        tags: ['health', 'monitor'],
        healthCheck: function(callback) {
            //Here you should preform your health checks
            //If something went wrong provide the callback with an error
            callback();
        }
    }
}, function (err) {

    if(err){
      console.log(err);
    }
});

server.start(function () {

  console.log('Server running at:', server.info.uri);
});

Calling the health route

The health route is exposed using GET method in a given path (/health by default).

When the server is healthy the response status code should be 200.

When the health check returns error the status code should be 400 and the payload should contain the error title.