Socket
Socket
Sign inDemoInstall

@flexshopper/hapi-handlers

Package Overview
Dependencies
20
Maintainers
6
Versions
5
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @flexshopper/hapi-handlers

Standard NPM package with Flexshopper coding standards and guidelines.


Version published
Weekly downloads
12
decreased by-14.29%
Maintainers
6
Install size
6.41 MB
Created
Weekly downloads
 

Readme

Source

@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' }
    },

Keywords

FAQs

Last updated on 22 Aug 2016

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc