Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@flexshopper/hapi-pres

Package Overview
Dependencies
Maintainers
6
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@flexshopper/hapi-pres

Hapi plugin to autoload pres.

  • 3.1.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
6
Created
Source

@flexshopper/hapi-pres

Build Status Dependencies Dev dependencies

Plugin to autoload pres based on patterns.

How to use:

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

Registering

Kraken service style:

const server = new Hapi.Server();

server.connection();

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

Manifest style:

registrations: [
    ...
    {
        plugin: {
            register: 'hapi-pres',
            options: {
                relativeTo: proccess.cwd() + '/pres',
                includes: ['path/to/**/*pres.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())

Pre-requirement Signature(Version 2.x.x and before)

const internals = module.exports = {};

internals.assign = 'myAwesomePre';
internals.method = (request, reply) => {
    return reply(request.query);
};

// then in the routes
server.route({
    method: 'GET',
    path: '/ping',
    config: {
        pre: [
             server.pre.myAwesomePre
        ],
        handler: (request, reply) => {
             return reply(request.pre.example);
        }
    }   
});

Pre-requirement Signature(Version 3.x.x and after)

// in you pre-handler file
const internals = module.exports = {};

internals.myAwesomePre = (request, reply) => {

    return reply('myAwesomePre');
}

internals.mySecondAwesomePre = (request, reply) => {
    
    return reply('mySecondAwesomePre');
}

// assume your pre-handler file name is my-Pre.js
// then in the routes
server.route({
    method: 'GET',
    path: '/ping',
    config: {
        pre: [
            server.pre.myPre.myAwesomePre,
            server.pre.myPre.mySecondAwesomePre
        ],
        handler: (request, reply) => {
            return reply('handler');
        }
    }
});

// if you need to get result from pre handler
request.pre.myAwesomePre
request.pre.mySecondAwesomePre

Cautions

  • Please do not name two different pre-handlers with same name, even in different files. Otherwise they won't be accessed correctly.

Keywords

FAQs

Package last updated on 29 Sep 2016

Did you know?

Socket

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc