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 { |
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 express, { Request } from 'express'; | |
import Context from './context' | |
const app = express(); | |
// Middleware | |
app.use((req: Request, res: any, next: any) => { | |
Context.bind(req); | |
next(); | |
}); |
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 express, { Request } from 'express'; | |
import Context from './context' | |
const app = express(); | |
// ... | |
app.get('/foo', (req: Request, res) => { | |
const ctx: Context = Context.get(req); | |
OlderNewer