を使用してリクエストの本文を検証しようとしていexpress-validator
ます。穴の本文は単一の配列であるため、フィールド名がありません。
バージョン 4の新しい API を使用していますexpress-validator
。express
本体は次のようになります。
["item1","item2"]
私のコード:
app.post('/mars/:Id/Id', [
check('id')
.isLength({ max: 10 })
.body() //try many ways to get the body. most examples i found were for the old api
.custom((item) => Array.isArray(item))
],
(req, res, next) => {
const data: string = matchedData(req); //using this method to only pass validated data to the business layer
return controller.mars(data); //id goes in data.id. i expect there should be an data.body once the body is validated too.
}
ボディを検証するにはどうすればよいですか?