Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Meteor Iron Router How to get POST data

I am trying to pass POST data to an Iron Router route from outside meteor but it doesn't work. The request body is empty.

I have tried outputting the request body to check if the data were present, but it's just empty.

Router.route('/api/gatewaysusers', function() {
        body = this.request.body;
        console.log(this.request)
        // this.response.write(body);
        this.response.end("Call served");


}, {where: 'server'})

Any idea ? Thank you.

like image 216
DanteDiaze Avatar asked Nov 04 '14 19:11

DanteDiaze


1 Answers

The request.body is empty because iron-router lacks middleware responsible for extracting url-encoded data. This is a BUG, which will be hopefully solved in later versions. For now you can just add:

Router.onBeforeAction(Iron.Router.bodyParser.urlencoded({
    extended: false
}));

somewhere on your server and it should work fine. Look here for more details.

like image 96
Tomasz Lenarcik Avatar answered Oct 18 '22 11:10

Tomasz Lenarcik