【问题标题】:Hapi: Error: Cannot set uncompiled validation rules without configuring a validatorHapi:错误:如果不配置验证器,则无法设置未编译的验证规则
【发布时间】:2020-04-05 01:59:06
【问题描述】:

这是我的 Package.json。我收到错误 Hapi:错误:如果不配置验证器,就无法设置未编译的验证规则。

    "@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();

【问题讨论】:

    标签: hapi


    【解决方案1】:

    我已经解决了这个问题: 这里是参考link

            validate: {
                query: >>>>{
                    name: Joi.string().required()
                   }<<<
            }
        },
    

    它应该是 Joi 模式而不是普通对象。

      options: {
            validate: {
                query:Joi.object({
                    name:Joi.string().required()
                     })
            }
        },
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-07-16
      • 2014-11-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-03-13
      • 1970-01-01
      • 2011-04-06
      相关资源
      最近更新 更多