express-http-context
Advanced tools
Comparing version
{ | ||
"name": "express-http-context", | ||
"version": "1.0.3", | ||
"version": "1.0.4", | ||
"description": "Get and set request-scoped context anywhere", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -15,4 +15,9 @@ [](https://travis-ci.org/skonves/express-http-context) | ||
Use the middleware. The earlier the better; you won't have access to the context from any middleware "used" before this one. | ||
Use the middleware immediately before the first middleware that needs to have access to the context. | ||
You won't have access to the context in any middleware "used" before this one. | ||
Note that some popular middlewares (such as body-parser, express-jwt) may cause context to get lost. | ||
To workaround such issues, you are advised to use any third party middleware that does NOT need the context | ||
BEFORE you use this middleware. | ||
``` js | ||
@@ -23,3 +28,4 @@ var express = require('express'); | ||
var app = express(); | ||
// Use any third party middleware that does not need access to the context here, e.g. | ||
// app.use(some3rdParty.middleware); | ||
app.use(httpContext.middleware); | ||
@@ -60,3 +66,2 @@ // all code from here on has access to the same context for each request | ||
1. Make sure you require `express-http-context` in the first row of your app. Some popular packages use async which breaks CLS. | ||
1. If you are using `body-parser` and context is getting lost, register it in express before you register `express-http-context`'s middleware. | ||
@@ -71,1 +76,2 @@ For users of Node 10 | ||
Amiram Korach (@amiram) | ||
Yoni Rabinovitch (@yonirab) |
7322
4.33%74
8.82%