Question

does the connect middleware prevent a middleware component from accidentally override a function that was a method of res? OR you just have to make sure you name it differently? So in this example you basically just messed up the body data, whats the best way to prevent this?

 .use(connect.bodyParser())
 .use(function(req,res,next){
      req.body=null;
 })
 .use(function(req,res){
      res.end(req.body);
 });
Was it helpful?

Solution

You can put everything in your own namespace if you're very worried about it:

app.use(function (req, res, next) {
  req.myappname.foo = null
  req.myappname.bar = null
});

Or just make absolutely sure it doesn't exist before you overwrite it. You can always do a manual check in a test script.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top