Open
Description
Hello everyone!
I need to save some important data every time when the response is already available.
I have tried 2 approaches:
api.finally
- does not allow us to use an async callback.
api.finally(async (req, res) => {
await saveAudit(req, res)
res.cors()
console.log('done')
})
- Tried to override the method
res.send
in a middleware - it looks like the send method can not include any async operations.
function auditHandler (handler) {
return (req, res, next) => {
res.sendRes= res.send
res.send = function (body) {
const data = {}
saveAudit(data)
.finally(() => {
console.log('finally', resData)
res.sendRes.call(this, body)
})
}
next()
}
}
As a result - the API does not work, but it works if we do not wait for an asynchronous operation.
Metadata
Metadata
Assignees
Labels
No labels