1.0.1 • Published 8 years ago

hapi-plugin-requestcontext v1.0.1

Weekly downloads
-
License
ISC
Repository
bitbucket
Last release
8 years ago

hapi-plugin-requestcontext

Installation

  1. Install as an NPM package from its private Asurion repository:

    $ npm install https://bitbucket.org/asurionwms/hapi-plugin-requestcontext.git
  2. 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();
  3. 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 to true.
  • asurionHeaders - Indicates whether the internal Asurion microserice HTTP headers should be read. Defaults to false.

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

  1. To run the test suite, first install the dependencies then run npm test:

    $ npm install
    $ npm test
  2. Analyze code coverage:

    $ npm run test-coverage

    An HTML copy of the coverage report will be written to the ./coverage directory.

  3. Check adherance to style guidelines and detect potential problems:

    $ npm run lint
  4. Check for known security exploits of dependent packages:

    $ npm run security
1.0.1

8 years ago