-
I've looked at this and this discussions and the code examples use |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
Hmm the title says you'd like to extend
Do you want to extend import { Router } from 'express';
export class CustomRouter {
constructor() {
Object.setPrototypeOf(this, Router.prototype);
return this;
}
} |
Beta Was this translation helpful? Give feedback.
-
I guess the original problem stems from the fact that the docs use the examples of middleware, which assign values directly to
Which is more-less equivalent to assigning to |
Beta Was this translation helpful? Give feedback.
I guess the original problem stems from the fact that the docs use the examples of middleware, which assign values directly to
req
object. This is somewhat of an antipattern, if only because it makes harder to tell apart the details of an http request and related business logic. And the typings don't allow to change theRequest
shape on per-route basis, so it's pretty annoying to express in types without extendingApplication
/Router
object/class directly.There is however
Response.locals
, the docs for which make it sound like it's something made for templates but the important part is here: