Repository navigation
|
I've looked at this and this discussions and the code examples use |
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;
}
} |
|
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 |
I guess the original problem stems from the fact that the docs use the examples of middleware, which assign values directly to
reqobject. 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 theRequestshape on per-route basis, so it's pretty annoying to express in types without extendingApplication/Routerobject/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: