Autoload Handlers for HapiJS.
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
lib
test
.gitignore
.travis.yml
CHANGELOG.md
CONTRIBUTORS.md
LICENSE
README.md
npm-shrinkwrap.json
package.json

README.md

hapi-handlers

Npm Version Build Status Dependencies Dev dependencies

NPM

Plugin to autoload handlers based on patterns.

How to use:

  • Install hapi-handlers npm package in your project our plugin. npm i hapi-handlers
  • Register plugin in your hapi server:

Registering

const server = new Hapi.Server();

server.connection();

server.register({
    register: require('hapi-handlers'),
    options: {
        includes: 'path/to/**/*Handlers.js' // uses glob to include files
    }
}, (err) => {
  // continue application
});

manifest style:

registrations: [
    ...
    {
        plugin: {
            register: 'hapi-handlers',
            options: {
                includes: 'path/to/**/*Handlers.js'
            }
        }
    }
];

Your handlers are available in your routes using the handle file name:

server.route({
    method: 'GET',
    path: '/route',
    config: {
        handler: {
            handlerName: {} // assuming your handle file is handlerName
        }
    }
})

Options

includes

Required
Type: string / array

The glob pattern you would like to include

ignores

Type: string / array

The pattern or an array of patterns to exclude

relativeTo

Type: string

The current working directory in which to search (defaults to process.cwd())

Handler Signature

'use strict';

module.exports = (route, options) => {

    return (request, reply) => {

        return reply({
            message: 'Hello World.'
        });
    };
};