我很好奇如何将参数传递给验证器中间件,摘录自快件-验证器,例如,将快件-验证器传递给check()函数。
const { check, oneOf, validationResult } = require('express-validator/check');
app.post('/start-freelancing', oneOf([
check('programming_language').isIn(['javascript', 'java', 'php']),
check('design_tools').isIn(['photoshop', 'gimp'])
]), (req, res, next) => {
try {
validationResult(req).throw();
// yay! we're good to start selling our skilled services :)))
res.json(...);
} catch (err) {
// Oh noes. This user doesn't have enough skills for this...
res.status(422).json(...);
}
});发布于 2018-04-19 07:39:18
check('programming_language')'programming_language‘是一个请求参数。不需要单独传递任何东西。它是从
req.body.programming_language
req.cookies.programming_language
req.headers.programming_language
req.params.programming_language
req.query.programming_language“design_tools”也是一样的
req.body.design_tools
req.cookies.design_tools
req.headers.design_tools
req.params.design_tools
req.query.design_toolshttps://stackoverflow.com/questions/49915229
复制相似问题