recourier

2.0.0 • Public • Published

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;
}

Dependents (3)

Package Sidebar

Install

npm i recourier

Weekly Downloads

3

Version

2.0.0

License

BSD-3-Clause

Last publish

Collaborators

  • ruiquelhas