سؤال

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);
 });
هل كانت مفيدة؟

المحلول

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.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top