Last active
September 9, 2020 18:33
-
-
Save thebigredgeek/dc545580a245bb25344f039bea128521 to your computer and use it in GitHub Desktop.
Context Class for Requests
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Request } from 'express'; | |
export default class Context { | |
static _bindings = new WeakMap<Request, Context>(); | |
public foo = 'bar'; | |
constructor () {} | |
static bind (req: Request) : void { | |
const ctx = new Context(); | |
Context._bindings.set(req, ctx); | |
} | |
static get (req: Request) : Context | null { | |
return Context._bindings.get(req) || null; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment