Im trying to use express-validator v4.3.0
to validate inputs to validate express inputs. I tried to follow the documentation but can't get it to work... It's not detecting any errors. Also it stalls in the route. I guess I'm missing the next()
function call. What am I missing?
This is my route:
routes.get(
"/localizations/apps/:app_name/locales/:locale_abbr_short",
validateParams,
fetchLocalization,
)
This is 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(),
]
}
You have to call the validateParams
function in order to return an array of validation middlewares:
routes.get(
"/localizations/apps/:app_name/locales/:locale_abbr_short",
validateParams(),
fetchLocalization,
)