1.0.1 • Published 8 years ago
hapi-plugin-requestcontext v1.0.1
hapi-plugin-requestcontext
Installation
Install as an NPM package from its private Asurion repository:
$ npm install https://bitbucket.org/asurionwms/hapi-plugin-requestcontext.git
Register the plugin before the server is started:
const Hapi = require('hapi'); const RequestContext = require('hapi-plugin-requestcontext'); const server = new Hapi.Server(); await server.register(RequestContext, { extendedHeaders: true, asurionHeaders: true }); await server.start();
Alternately, register the plugin using a Glue manifest:
{ "registrations": [ { "plugin": { "register": "hapi-plugin-requestcontext", "options": { "extendedHeaders": true, "asurionHeaders": true } } } ] }
Usage
This plugin reads contextual headers during each request and places them in a new request.app.context
object.
Registration options
The plugin accepts the following registration options:
extendedHeaders
- Indicates whether the x-correlation-id header should be read. Defaults totrue
.asurionHeaders
- Indicates whether the internal Asurion microserice HTTP headers should be read. Defaults tofalse
.
Context object
The request.app.context
object will contain the following fields if they can be read as headers:
correlationId
client
region
channel
interactionLineId
lineOfBusiness
user
Tests
To run the test suite, first install the dependencies then run
npm test
:$ npm install $ npm test
Analyze code coverage:
$ npm run test-coverage
An HTML copy of the coverage report will be written to the
./coverage
directory.Check adherance to style guidelines and detect potential problems:
$ npm run lint
Check for known security exploits of dependent packages:
$ npm run security
1.0.1
8 years ago