[英]ArangoDB Foxx pathParam is undefined
Made a new Foxx app with the Web UI and added the following route: 使用Web UI制作了一个新的Foxx应用程序,并添加了以下路线:
controller.get('/names/:name', function (request, response) {
var name = request.params('name');
response.json(db._query(
"FOR x IN collection"+
" FILTER x.name == " + name +
" RETURN x"
).toArray());
})
.pathParam('name', { // line 112
description: 'A name value to search for',
type: 'String'
})
.errorResponse(ArangoError, 404, 'Data not found');
Which gives an error pointing to line 112 and prevents the app from running: 这给出了指向第112行的错误,并阻止了应用程序的运行:
This runs fine if the .pathParam
function is removed. 如果删除.pathParam
函数,则此方法运行良好。
How can I fix this/what am I doing wrong? 我该如何解决/我在做什么错? I'm using a fresh install with version 2.6.9 (latest) 我正在使用2.6.9版(最新)进行全新安装
AFAIK the type
sub-attribute in .pathParam()'s second parameter was changed in version 2.5 to use joi. AFAIK .pathParam()的第二个参数中的type
子属性在版本2.5中已更改为使用joi。 So it needs to be changed to: 因此需要将其更改为:
.pathParam('name', { // line 112
description: 'A name value to search for',
type: joi.string() // this line needs changing
})
Apart from that, you will need to require
joi in the controller beforehand, ie 除此之外,您需要预先在控制器中require
joi,即
var joi = require('joi');
That tutorial is indeed out of date and needs fixing. 该教程确实已经过时,需要修复。
So, according to the latest controller docs , it seems the use of joi is now required. 因此,根据最新的控制器文档 ,似乎现在需要使用joi。
Reason for the error was, I was following the Foxx tutorial which doesn't use joi. 该错误的原因是,我正在关注不使用joi的Foxx教程 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.