Configuring Restivus POST method for Meteor

怎甘沉沦 提交于 2019-12-23 03:12:40

问题


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;
            }
        }
    })

}

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.

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)

Knowing that, I know my error is in the Restivus Route configuration, but I cannot pinpoint the reason.

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).

Additional question, is there a way to disable the default GET method Restivus creates when we add a collection?


回答1:


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);
...


来源:https://stackoverflow.com/questions/30581774/configuring-restivus-post-method-for-meteor

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!