Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
NotificationsYou must be signed in to change notification settings

marcelorl/hapi-request-context-2

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

28 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Build StatusGreenkeeper badge

Sets values on the CLS context for each request.

It means:

  • You also have the ability to set values from Http Header directly in the plugin setup;
  • Or set a context value at any moment in your request lifecycle

Make sure that you require the module the first time in yor index.js (or however your applicatioon entrypoint is named) to make sure that the context gets created correctly.

Installation

$ npm i hapi-request-context-2 --save

Usage

consthapiRequestContext=require('hapi-request-context-2');// hapi plugin installation{register:hapiRequestContext,options:{mapHeaders:['authorization']// it will store 'authorization' in your context}},// Also, if you want to set an id for each requestserver.ext('onPreHandler',(request,reply)=>{hapiRequestContext.context().set('requestId',shortid.generate())returnreply.continue()})// Then whenever you want to recover ithapiRequestContext.context().get('authorization')hapiRequestContext.context().get('requestId')

Play with it!!!11! =)

Credits

I have copied this code fromhapi-request-context package. I have applied few fixed to the code, since it seems the packageis not mantained anymore and I needed it to work properly.

ps. I couldn't fork it because the original repo is placed on bitbucket =/.

What did I do?

  • Replacedcontinuous-local-storage package tocls-hooked.cls has some known issues with async/await requests wherethe data set with it gets lost and doesnt travel through the entire request proccess;
  • Better README.md;
  • Fixed all npm package vulnerabilities.

Compability

It was tested only with Hapi 16. If you would like to use it with other version, please open an issue or aPR (even better :p).

License

BSD

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors3

  •  
  •  
  •  

[8]ページ先頭

©2009-2025 Movatter.jp