express-validator array params
var express = require("@runkit/runkit/express-endpoint/1.0.0");
const { checkSchema, validationResult } = require("express-validator/check");
var app = express(exports);
app.get(
"/a",
checkSchema({
foo: {
in: "query",
isAlphanumeric: true,
optional: true,
},
}),
handler
);
app.get(
"/b",
checkSchema({
'foo.*': {
in: "query",
isAlphanumeric: true,
optional: true,
},
}),
handler
);
function handler(req, res) {
const errors = validationResult(req);
if (!errors.isEmpty()) {
res.status(400).send({ errors: errors.array() });
} else {
res.send({
foo: req.query.foo,
});
}
}
no comments