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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With