POST from Ruby to Meteor with Iron Router?

2019-09-18 04:33发布

I've been trying to get a message from a Ruby script to a webapp built with MeteorJS using POST, but I've been facing some issues. There isn't much documentation online about POST and GET method management with Iron Router.

My Ruby script:

meteorUri = URI('http://localhost:3000/newReport');
res = Net::HTTP.post_form(meteorUri, 'message' => 'HelloFromRuby', 'max' => '50')
puts "From Meteor:\t#{res}"

I don't have much experience with Ruby. The above code I got mostly online.

The routing with Iron Router:

 Router.route('/newReport/:message', {where: 'server'})

    .post( function(message){

        Meteor.call('reportInsert', {message: message}, function(error, recordId){

            if (error){
                alert(error.reason);
            } else {
                console.log("Inserted " + recordId);
            }

        });
    });

I am trying to make Ruby make a post to http://localhost:3000/newReportwith a message that is supposed to be a string.

The function reportInsert works, I tested it. The issue seems to be in either making the POST, or receiving it.

Thank you!

1条回答
Ridiculous、
2楼-- · 2019-09-18 05:03

Beside using an alert in a server side route, I don't see any issues on Meteor's side. Might want to change it to console.log to see what error are you getting.

查看更多
登录 后发表回答