Hapi: Error: Cannot set uncompiled validation rules without configuring a validator

試著忘記壹切 提交于 2021-01-29 09:40:57

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!