Giter Site home page Giter Site logo

hapi-alive's Introduction

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

hapi-alive's People

Contributors

idoshamun avatar dependabot[bot] avatar lostthetrail avatar koenighotze avatar mellisdesigns avatar stevenceuppens avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.