Skip to content

Instantly share code, notes, and snippets.

@nfroidure
Last active November 6, 2016 09:41
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 nfroidure/3c0a5858518663be186a1a64d160ee31 to your computer and use it in GitHub Desktop.
Save nfroidure/3c0a5858518663be186a1a64d160ee31 to your computer and use it in GitHub Desktop.
Express midlewares hell
module.exports = (app) => {
// where ther hell is this config set?
const config = app.get('config');
// How can i see what this timer do?
const timer = app.get('timer');
app.post((req, res, next) => {
const data = {};
// Which middleware set up this query params?
if(req.query.ms) {
data.when = timer.now();
} else {
data.when = new Date(timer.now()).toISOString();
}
// How this body was set, in which middleware?
if(config.repeatBody) {
data.body = req.body;
}
res.jsonBody = data; // Which consequences setting that jsonBody has?
next(); // What happens then? New headers? Body transformations?
})
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment