Created
July 2, 2021 05:08
-
-
Save PsyGik/615fcd63bb8f2e04d9540d9d96fa7768 to your computer and use it in GitHub Desktop.
Express Request Headers
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Let Next.js handle rest of the routes | |
function modifyResponseBody(req, res, next) { | |
var oldSend = res.send; | |
res.send = function (data) { | |
// arguments[0] (or `data`) contains the response body | |
arguments[0] = 'modified : ' + arguments[0]; | |
oldSend.apply(res, arguments); | |
}; | |
res.on('finish', function () { | |
console.log( | |
`${new Date()} ${req.method} request received on ${req.url} with code ${ | |
this.statusCode | |
} and Cache-Control ${res.get('Cache-Control')}` | |
); | |
}); | |
next(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment