Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Context Class for Requests
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