Skip to content

Instantly share code, notes, and snippets.

@PsyGik
Created July 2, 2021 05:08
Show Gist options
  • Save PsyGik/615fcd63bb8f2e04d9540d9d96fa7768 to your computer and use it in GitHub Desktop.
Save PsyGik/615fcd63bb8f2e04d9540d9d96fa7768 to your computer and use it in GitHub Desktop.
Express Request Headers
// 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