我正在尝试使用joi包在Hapi节点服务器中验证GET请求。验证正在按预期正确工作。但是,如果没有传递参数,我很难找到返回错误的方法。目前,如果没有传递参数,则成功。另外,是否有一种方法来修改正在发送的响应?
var Hapi = require('hapi');
var Joi = require('joi');
var server = module.exports = new Hapi.Server();
server.connection({
host : process.env.HOST,
port : 3000
});
serve
由于以下原因,在我的项目中安装东西时,我会出现许多警告: warning @hapi/hapi > @hapi/joi@17.1.1: joi is leaving the @hapi organization and moving back to 'joi'
(https://github.com/sideway/joi/issues/2411)
warning @hapi/hapi > @hapi/catbox > @hapi/joi@17.1.1: joi is leaving the @hapi organization and
moving b
将Joi升级到最新版本@hapi/Joi(17.1.1)后,我的服务器没有启动,启动时出现以下错误。在最近的版本中似乎有一些突破性的变化。不能得到任何线索,任何帮助是感激的。
Error: Schema can only contain plain objects (name)
at new module.exports (/Users/xyz/project/projectxyz/node_modules/@hapi/hoek/lib/error.js:23:19)
at module.exports (/Users/xyz/project/projectxyz/node_m
我有以下JavaScript代码来测试Hapi/Joi验证函数:
var Joi = require('joi');
var schema = { free: Joi.Types.Number().float() };
var value = { free: 3.3333 };
var err = Joi.validate(value, schema);
//err is set if value fails to validate against the schema
if (err) throw err;
验证抛出错误:
Error: the value of free
我必须使用Joi验证库在API输入中进行验证,因此发送输出。
我说创建了一个模式,如下所示:
import Joi from '@hapi/joi'
const eventSchema = Joi.object({
title: Joi.string()
.min(7)
.max(50)
.required()
.error(() => Error('Event title has to be least 7 and max 50 characters.')),
description: Joi.string()
我有一个用例,需要向我的Hapi后端发送一系列文件。我在React客户机中找到的最好的方法是使用FormData。这种方法在Hapi和Joi的旧版本("hapi": "^17.8.1","joi": "^13.7.0")上非常有效。但是,在升级了我的Hapi和Joi ("@hapi/hapi": "^20.2.1","joi": "^17.5.0")之后,我对Joi拒绝使用"files[]" must be an array的文件数组有问题。知道更新后
我不明白为什么我收到导入了"@hapi/joi":"^17.0.0“和”@ Property 'validate' does not exist on type 'Root'.ts(2339) /hapi__joi“:"^16.0.6”的错误类型和Parameter 'err' implicitly has an 'any' type.ts(7006)。 import Joi from '@hapi/joi';
import { NextFunction, Request, Res
由于某些原因,当我使用nodemon启动我的hapi服务器并导航到时,服务器控制台中没有出现错误,这使得调试非常困难。这是我的代码:
var Hapi = require('hapi');
var Joi = require('joi');
var fetch = require('isomorphic-fetch');
var debugMode = { debug: { request: [ 'error', 'request-internal' ] }};
var server = new Hapi.Ser