如何防止节点js express中的不需要的请求?

时间:2020-09-28 10:13:14

标签: node.js express request request.querystring

预期的请求:

{
    "name": "Raju",
    "email": "email@email.com"
}

实际:

{
    "name": "Raju",
    "email": "email@email.com",
    "xyz" : "xxxx"
}

我想在验证/路由器级别为“ xyz”抛出错误或转义。 我正在使用最快的验证程序。

还有其他验证器支持此功能吗?

任何帮助表示赞赏

1 个答案:

答案 0 :(得分:0)

您可以像以下示例一样设置$$strict: true

const schema = {
    name: { type: "string" }, // required
    $$strict: true // no additional properties allowed
}

v.validate({ name: "John" }, schema); // Valid
v.validate({ name: "John", age: 42 }, schema); // Fail
相关问题