Created
October 22, 2019 12:12
-
-
Save asolera/feab858bed538f65bbea18539a6f824d to your computer and use it in GitHub Desktop.
ExpressJS - Interceptando responses (inclusão de logs) utilizando express-interceptor
This file contains 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
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