Skip to content

Is there a way to extend Router using only ES6 sublass syntax? #5018

Answered by GabenGar
GabenGar asked this question in Q&A
Discussion options

You must be logged in to vote

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 the Request shape on per-route basis, so it's pretty annoying to express in types without extending Application/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:

The variables set on res.locals are available within a single request-response cycle, and will not…

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
1 reply
@GabenGar
Comment options

Comment options

You must be logged in to vote
0 replies
Answer selected by GabenGar
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
2 participants