express-http-context
Advanced tools
Comparing version
@@ -0,1 +1,3 @@ | ||
import { AsyncLocalStorage } from 'async_hooks'; | ||
/** Express.js middleware that is responsible for initializing the context for each request. */ | ||
@@ -17,1 +19,6 @@ export declare function middleware( | ||
export declare function set(key: string, value: any): void; | ||
/** | ||
* Gets the instance of AsyncLocalStorage that is used to store the context for each request. | ||
*/ | ||
export declare const asyncLocalStorage: AsyncLocalStorage<Map<string, unknown>>; |
@@ -8,3 +8,7 @@ 'use strict'; | ||
function middleware(req, res, next) { | ||
asyncLocalStorage.run(new Map(), next); | ||
if (!asyncLocalStorage.getStore()) { | ||
asyncLocalStorage.run(new Map(), () => next()); | ||
} else { | ||
next(); | ||
} | ||
} | ||
@@ -36,3 +40,4 @@ | ||
get: get, | ||
set: set | ||
set: set, | ||
asyncLocalStorage | ||
}; |
{ | ||
"name": "express-http-context", | ||
"version": "2.0.0-rc.3", | ||
"version": "2.0.0-rc.4", | ||
"description": "Get and set request-scoped context anywhere", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
6721
5.18%66
17.86%