문제

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