Closed Akkuma closed 5 years ago
Hi @Akkuma , thanks for taking time on restana. I am afraid to say that your fix won't work as expected. Here I expose several reasons:
next()
not async
ones. The goal was to re-use existing express and connect middlewares. However, you can benefit from the on response
event to get the same functionality:
service.use((req, res, next) => {
const now = new Date().getTime()
res.on('response', ({ res }) => {
res.setHeader('x-response-time', new Date().getTime() - now)
})
return next()
})
You are required to use
req.send(...)
to get this event triggered.
Looking forward to your feedback, Thanks and Regards
By returning the result, middleware can now be properly asynchronous throughout the project, so you can write code like this: