问题
Here is my Package.json. I was getting error Hapi: Error: Cannot set uncompiled validation rules without configuring a validator.
"@hapi/boom": "^9.1.0", "@hapi/hapi": "^19.1.1", "@hapi/inert": "^6.0.1", "@hapi/joi": "^17.1.1", "@hapi/vision": "^6.0.0",
const Hapi = require("@hapi/hapi");
const Joi = require("@hapi/joi")
const server = new Hapi.Server({ host: "localhost", port: 8003 });
server.route({
method: "GET",
path: "/helloWorld",
options: {
validate: {
query: {
name: Joi.string().required()
}
}
},
handler: async (request, h) => {
return 'Hapi'
}
});
server.start();
回答1:
I have Solve by this: Here is the reference link:
validate: { query: >>>>{ name: Joi.string().required() }<<< } },
It should be Joi schema not a plain object.
options: {
validate: {
query:Joi.object({
name:Joi.string().required()
})
}
},
来源:https://stackoverflow.com/questions/61032256/hapi-error-cannot-set-uncompiled-validation-rules-without-configuring-a-valida