Last active
November 6, 2016 09:41
-
-
Save nfroidure/3c0a5858518663be186a1a64d160ee31 to your computer and use it in GitHub Desktop.
Express midlewares hell
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
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