Nice Philanthropist Metalhead
    Share your code. npm Orgs help your team discover, share, and reuse code. Create a free org »

    @plan3-relate/hapi-clspublic

    Continuation Local Storage for Hapi Build Status

    Heavily "inspired" on https://github.com/entrinsik-org/hapi-cls

    Ref: https://www.npmjs.com/package/continuation-local-storage

    This Hapi plugin installs CLS and binds it to the request

    Installation

    npm install @smp-relate/hapi-cls

    Usage

    const server = new hapi.Server();
    server.connection({port: config.port});
     
    server.register(require('@smp-relate/hapi-cls'), {namespace: 'my-namespace'})

    NOTE: Registration should be done in the "highest" point possible to ensure other plugins are also working in the CLS context.

    Value setting

    There's a hook enabling setting custom values in the request context right after it's initialized. Requires value resolution function that receives request object as an argument. Example:

    const server = new hapi.Server();
    server.connection({port: config.port});
     
    server.register(require('@smp-relate/hapi-cls'), {namespace: 'my-namespace', set: {
        customValue: (request) => request.headers['x-custom-header']
    }});

    License

    ISC

    Keywords

    install

    npm i @plan3-relate/hapi-cls

    Downloadslast 7 days

    15

    version

    1.0.0

    license

    ISC

    repository

    github.com

    last publish

    collaborators

    • avatar