Skip to content

Instantly share code, notes, and snippets.

@asolera
Created October 22, 2019 12:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save asolera/feab858bed538f65bbea18539a6f824d to your computer and use it in GitHub Desktop.
Save asolera/feab858bed538f65bbea18539a6f824d to your computer and use it in GitHub Desktop.
ExpressJS - Interceptando responses (inclusão de logs) utilizando express-interceptor
const express = require('express');
const app = express();
const interceptor = require('express-interceptor');
const responseInterceptor = interceptor((req, res) => {
return {
isInterceptable: () => true,
intercept: (body, send) => {
console.log('Intercepted!');
send(body);
}
};
});
app.use(responseInterceptor);
const APP_PORT = process.env.APP_PORT || 3000;
app.listen(APP_PORT, () => {
console.log(`App listening on port ${APP_PORT}...`);
});
app.get('/', (req, res) => {
res.send(`Hello World!`);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment