@flexshopper/hapi-handlers
Standard NPM package with Flexshopper coding standards and guidelines.
Last updated 4 years ago by ar4mirez .
ISC · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install @flexshopper/hapi-handlers 
SYNC missed versions from official npm registry.

@flexshopper/hapi-handlers

Build Status Dependencies Dev dependencies

Plugin to autoload handlers based on patterns.

How to use:

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

Registering

const server = new Hapi.Server();

server.connection();

server.register({
    register: require('hapi-handlers'),
    options: {
        relativeTo: proccess.cwd() + '/handlers',
        includes: ['path/to/**/*Handlers.js'],
        ignore: ['*.git'],
    }
}, (err) => {
  // continue application
});

manifest style:

registrations: [
    ...
    {
        plugin: {
            register: 'hapi-handlers',
            options: {
                relativeTo: proccess.cwd() + '/handlers',
                includes: ['path/to/**/*Handlers.js'],
                ignore: ['*.git'],
            }
        }
    }
];

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: array

The glob pattern you would like to include

ignore

Type: 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.'
        });
    };
};

Filename adapting

No matter what format your filenames are in, use camelcase to access the method.

For example, if a handler file name is: foo-bar.js with a method 'myMethod'. You can get access to it as:

    handler: {
        fooBar: { method: 'myMethod' }
    },

Current Tags

  • 3.0.0                                ...           latest (4 years ago)

5 Versions

  • 3.0.0                                ...           4 years ago
  • 2.0.1                                ...           4 years ago
  • 2.0.0                                ...           4 years ago
  • 1.1.8                                ...           4 years ago
  • 1.1.7                                ...           4 years ago
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 6
Dependencies (5)
Dev Dependencies (11)
Dependents (0)
None

Copyright 2014 - 2016 © taobao.org |