Socket
Socket
Sign inDemoInstall

@flexshopper/hapi-methods

Package Overview
Dependencies
19
Maintainers
7
Versions
6
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @flexshopper/hapi-methods

Hapi plugin to autoload methods.


Version published
Weekly downloads
13
decreased by-81.69%
Maintainers
7
Install size
6.41 MB
Created
Weekly downloads
 

Readme

Source

@flexshopper/hapi-methods

Build Status Dependencies Dev dependencies

Plugin to autoload methods based on patterns.

How to use:

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

Registering

const server = new Hapi.Server();

server.connection();

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

manifest style:

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

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())

Route Signature
'use strict';

const internals = module.exports = {};

internals.myNewMethod = {

    method: (next) => {
        return next();
    },
    options: {
        cache: {
            expiresIn: 60000,
            generateTimeout: 60000
        }
    }
};

internals.anotherMethod = {

    // if method is defined as function(), 'this' value is bound to server instance
    method: function(next) {

        // 'this' is bound to server, thus it is equal to hapi server instance
        expect(this.plugins).to.exist();

        return next();
    }
};

// This methods would be available as:

server.methods.methodFileName.myNewMethod();
server.methods.methodFileName.anotherMethod();

Filename adapting

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

For example, if a method file name is: foo-bar.js, it has a method named myMethod() inside. You can access this method as:

server.methods.fooBar.myMethod();

'this' binding

If internals.anotherMethod.method is equal to regular function (non-arrow function) 'this' will be bound to instance of server.

Keywords

FAQs

Last updated on 23 Jan 2017

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