hapi-alive
Health route for your Hapi.js server
Last updated 7 months ago by idoesh .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install hapi-alive 
SYNC missed versions from official npm registry.

hapi-alive

Build Status Code Climate Test Coverage

Health route for your hapi.js server

Requirements

  • Node 8+
  • Hapi 17+

Usage

Install from NPM

npm install --save hapi-alive

Options

The defaults are as described below. You can override any defaults by passing them in as options.

const defaults = {
    path: '/health',
    tags: ['health', 'monitor'],
    responses: {
        healthy: {
            message: 'I\'m healthy!!!'
        },
        unhealthy: {
            statusCode: 400
        }
    },
    healthCheck: async function (_server) {

        return await true;
    },
    auth: false
};

Example

var Hapi = require('hapi');

async function createServer() {
    const server = Hapi.Server();

    // Register alive plugin
    await server.register({
        plugin: require('hapi-alive'),
        options: {
            path: '/health', //Health route path
            tags: ['health', 'monitor'],
            healthCheck: async function(server) {
                //Here you should preform your health checks
                //If something went wrong , throw an error.
                if (somethingFailed) {
                    throw new Error('Server not healthy');
                }
                return await true;
            }
        }
    });

    await server.start();

    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.

Change Log

  • v2.0.0 (Nov. 30th, 2017) Upgrade to Hapi 17
    • Hapi.js 17 suite of tool upgraded to latest.
    • healthCheck API converted to async/await pattern. Callback is no longer accepted.
  • v1.2.0
  • v1.1.0
  • v1.0.0

Current Tags

  • 2.0.4                                ...           latest (7 months ago)

10 Versions

  • 2.0.4                                ...           7 months ago
  • 2.0.3                                ...           9 months ago
  • 2.0.2                                ...           9 months ago
  • 2.0.1                                ...           a year ago
  • 2.0.0                                ...           2 years ago
  • 1.4.0                                ...           4 years ago
  • 1.3.0                                ...           4 years ago
  • 1.2.0                                ...           4 years ago
  • 1.1.0                                ...           4 years ago
  • 1.0.0                                ...           4 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 12
Last Day 0
Last Week 12
Last Month 16
Dependencies (3)
Dev Dependencies (3)

Copyright 2014 - 2016 © taobao.org |