【发布时间】:2019-02-28 21:52:39
【问题描述】:
我正在运行 NodeJS 和 joi,并且正在尝试验证 IBM Watson IoT 配置对象。
这是我的架构:
const schema = {
body: {
config: Joi.object().keys({
org: Joi.string().required(),
type: Joi.string().required(),
id: Joi.string().required(),
domain: Joi.string().required(),
'auth-method': Joi.string().required(),
'auth-token': Joi.string().required()
}).required()
}
};
这是我的支票:
Joi.validate(req.body, schema, { allowUnknown: true }, (err, value) => {
console.log(err);
});
这会将null 作为error 返回,这表明没有错误,但即使我没有POST 向我的主体添加任何参数。
基本上我想确保我的HTTP POST 的body 包含有效的JSON 对象,如下所示:
config = {
"org" : "organization",
"id" : "deviceId",
"domain": "internetofthings.ibmcloud.com",
"type" : "deviceType",
"auth-method" : "token",
"auth-token" : "authToken"
};
【问题讨论】:
-
您在尝试打印
error时在参数中使用err -
对不起,这里的错字。有问题已更正。
标签: javascript node.js joi