gpt4 book ai didi

rest - 为 Meteor 配置 Restivus POST 方法

转载 作者:可可西里 更新时间:2023-11-01 17:08:37 27 4
gpt4 key购买 nike

我有以下 Restivus 配置:

if(Meteor.isServer){

Restivus.configure({
});

//Allow Restivus to manage Reports
Restivus.addCollection('reports');

Restivus.addRoute('newReport/:message', {}, {

// POST
post: {
action: function(){

var response = null;
var message = this.urlParams.message;

if(message){
console.log("Message received: " + message);
return {status: "success", data: message};
} else {
console.log("Message empty...");
return {status: "fail", message: "Post not found"};
}

//Response to caller
return;
}
}
})

}

根据 Restivus 的解释,当我对 http://localhost:3000/api/newReport/ 进行 GET 调用时,我应该从服务器获得“全部获取”结果,在来电者。

但是,如果我在命令行上使用 curl -X GET http://localhost:3000/api/newReport/,我似乎在 api/获取站点的 HTML 代码NewReport/(除标题和空主体外为空)

知道了,我知道我的错误在 Restivus Route 配置中,但我无法查明原因。

预期的行为是,当我从 Ruby 脚本进行 POST 时,我应该得到一条返回消息(Ok 或 Fail),并且在我的 Meteor 控制台中,我应该看到“收到消息”或“找不到帖子” (都是占位符)。

附加问题,有没有办法禁用 Restivus 在我们添加集合时创建的默认 GET 方法?

最佳答案

您必须在 JavaScript 部分创建一个变量并在 Restivus.addCollection() 调用中使用它。

Reports = Mongo.Collection('reports')

if(Meteor.isServer){

Restivus.configure({
});

//Allow Restivus to manage Reports
Restivus.addCollection(Reports);
...

关于rest - 为 Meteor 配置 Restivus POST 方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30581774/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com