📜  没有中间件的节点 js 验证正文 - Javascript 代码示例

📅  最后修改于: 2022-03-11 15:01:25.197000             🧑  作者: Mango

代码示例1
function validateRegForm(req, res, next){
  console.log('Validating form...');
  if(!req.body.password){
    return res.send(500, 'Need a password');
  };
  next();
};

app.post('/regForm'
, validateRegForm
, function(req,res){
  // If Express calls this fn, the previous fn did next(), not res.send()
  console.log('Doing something with this valid form');
  res.redirect('/regForm/complete');
});