为Meteor配置Restivus POST方法 [英] Configuring Restivus POST method for Meteor
问题描述
我有以下Restivus配置:
I have the following Restivus configuration:
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,当我对GET调用 http:// localhost:3000 / api / newReport /
我应该得到一个Get All结果从服务器,在
Following the explanation of Restivus, when I make a GET call to http://localhost:3000/api/newReport/
I should get a "Get All" result from the server, on the caller.
但是,如果我使用 curl -X GET http:// localhost:3000 / api / newReport /
在命令行上,我似乎得到的网站的HTML代码在api / NewReport /(它是空的,除了标题和空主体)
However, if I use curl -X GET http://localhost:3000/api/newReport/
on the command line, I seem to be getting the HTML code of the site at api/NewReport/ (which is empty, except for the header and empty body)
知道了,我知道我的错误是在Restivus路由配置,但我不能找出原因。
Knowing that, I know my error is in the Restivus Route configuration, but I cannot pinpoint the reason.
预期的行为是,当我从Ruby脚本进行POST时,我应该得到一个返回的消息(Ok或Fail),在我的Meteor控制台中,请参阅收到消息或找不到帖子(两个占位符)。
The expected behavior is that when I make a POST from a Ruby script, I should get a returned message (Ok or Fail), and in my Meteor console, I should see either "Message received" or "Post not found" (both placeholders).
另外一个问题是,有一种方法可以禁用Restivus在添加时创建的默认GET方法一个集合?
Additional question, is there a way to disable the default GET method Restivus creates when we add a collection?
推荐答案
您必须在JavaScript部分中创建一个变量,并在Restivus.addCollection
You have to create a variable in the JavaScript part and use that in the Restivus.addCollection() call.
Reports = Mongo.Collection('reports')
if(Meteor.isServer){
Restivus.configure({
});
//Allow Restivus to manage Reports
Restivus.addCollection(Reports);
...
这篇关于为Meteor配置Restivus POST方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!