Closed FaberVitale closed 2 years ago
Sounds good - think we should investigate whether either of these would be best implemented first in the std http library for Deno, but certainly wouldn’t be much work to add to Opine itself (either custom or hanging off of the std http methods).
I believe there is already a done
or similar promise on the request object which could be used for one of these hooks?
What was the decision on this? I'm wanting to write a response-time middleware in one of the following ways:
To log response-time in opine, is there a way to do the following without splitting the logic into two separate middlewares?
app
.use(getStart)
.use(routes)
.use(getFinishAndLogTimeDelta)
@jly36963 no decision as such 🙃 issue remained unchanged and not worked on for over a year so closed as stale. If it's something you're keen on / have ideas on implementation then happy to reopen! 😄
@asos-craigmorten If I can find a simple solution I'll open a PR 😄
Issue
In node there are libraries like on-headers and on-finished that are commonly use to run logic before and after a request has been processed, some example:
morgan
session
It would be nice to port some of these projects to opine but it is not currently as easy as it should for a middleware to be called back when one of these events occurs:
Before
req.respond
: An async response is complete (e.g db returns output) and we are going to call request.respond.After
req.respond
: A request has been processed and the response has been sent, essentially the output ofrequest.respond
.Suggested Changes
Add a getter that returns a lazily instantiated and cached promise that resolves before calling request.respond.
Add a getter that exposes the output of request.respond.