Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including recourier with all npm packages installed. Try it out:

var recourier = require("recourier")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

recourier v2.0.0

Immutable request properties for hapi

recourier

Immutable request properties for hapi.

NPM Version Build Status Coverage Status Dependencies Dev Dependencies

Table of Contents

Installation

Install via NPM.

$ npm install recourier

Usage

Register the package as a server plugin, providing an optional namespace where the properties will be available during the request lifecycle (in case you want to access them during that period) and the list of the hapi request properties you effectively want to make immutable.

The initial values of those properties (i.e. when they are parsed by the onPostAuth extension point) will be saved in that immutable application namespace, which will then be again available in the request handler itself.

Example 1

Avoid plugin registration ordering issues by registering Recourier in the last place.

const Hapi = require('hapi');
const Recourier = require('recourier');
const MyPlugin = require('my-plugin');

const plugins = [{
    plugin: MyPlugin
}, {
    // any additional plugins
}, {
    plugin: Recourier,
    options: {
        namespace: 'foo', // defaults to 'recourier'
        properties: ['payload'] // immutable request properties
    }
}];

try {
    const server = new Hapi.Server();

    await server.register(plugins);
    await server.start();
}
catch (err) {
    throw err;
}

Example 2

Avoid plugin registration ordering issues by using server.dependency().

const Hapi = require('hapi');
const Recourier = require('recourier');

const MyPlugin = {
    name: 'my-plugin',
    register: (server, options) => {

        server.dependency(Recourier.pkg.name, (app) => {
            // go nuts
        });
    }
};

const plugins = [{
    plugin: Recourier,
    options: {
        namespace: 'foo', // defaults to 'recourier'
        properties: ['payload'] // immutable request properties
    }
}, {
    plugin: MyPlugin
}, {
    // any additional plugins
}];

try {
    const server = new Hapi.Server();

    await server.register(plugins);
    await server.start();
}
catch (err) {
    throw err;
}
RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free