我尝试使用express-validator v4.3.0
验证输入以验证快速输入。我试图按照文档但无法使其工作......它没有检测到任何错误。它也在路上停了下来。我想我错过了next()
函数调用。我错过了什么?
这是我的路线:
routes.get(
"/localizations/apps/:app_name/locales/:locale_abbr_short",
validateParams,
fetchLocalization,
)
这是validateParams
:
export async function validateParams() {
const allowedAppNames = ['common','webcalc_v2']
const allowedLocales= ['dk']
return [
check('app_name').isIn(allowedAppNames).withMessage('App name is unknown').trim(),
check('locale_abbr_short').isIn(allowedLocales).withMessage('Locale is unknown').trim(),
check('provider').isNumeric().withMessage('Provider id must be a number').trim(),
]
}
答案 0 :(得分:1)
您必须调用validateParams
函数才能返回一组验证中间件:
routes.get(
"/localizations/apps/:app_name/locales/:locale_abbr_short",
validateParams(),
fetchLocalization,
)