recourier
Immutable request properties for hapi.
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 = ;const Recourier = ;const MyPlugin = ; const plugins = plugin: MyPlugin // any additional plugins plugin: Recourier options: namespace: 'foo' // defaults to 'recourier' properties: 'payload' // immutable request properties ; try const server = ; await server; await serverstart;catch err throw err;
Example 2
Avoid plugin registration ordering issues by using server.dependency()
.
const Hapi = ;const Recourier = ; const MyPlugin = name: 'my-plugin' { server; }; const plugins = plugin: Recourier options: namespace: 'foo' // defaults to 'recourier' properties: 'payload' // immutable request properties plugin: MyPlugin // any additional plugins; try const server = ; await server; await serverstart;catch err throw err;