1

我试图用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(),
  ]
}
4

1 回答 1

1

您必须调用该validateParams函数才能返回一组验证中间件:

routes.get(
    "/localizations/apps/:app_name/locales/:locale_abbr_short",
    validateParams(),
    fetchLocalization,
)
于 2018-02-02T12:26:36.723 回答