Reputation: 1004
I am trying to create a middleware function that fires when the request has ended.
middleware
module.exports = function(req, res, next) {
req.on("end", function() {
console.log('End');
});
next();
};
I include my middleware like this.
app.all('/*', [require('./middlewares/activityLogger.js')]);
at the moment i see "END in console for GET request but not for POST, PUT and DELETE"
example of how i end request GET (WORKS)
res.status(200).json(result)
POST (Don't work)
res.status(201).json(result.create)
any suggesting to why my middleware function is only fired on GET requests?
Upvotes: 0
Views: 154
Reputation: 1004
Solved it by listening to the "finish" event instead of "end"
module.exports = function(req, res, next) {
res.on('finish', function() {
console.log('finish');
});
next();
};
Upvotes: 1