Meteor Iron Router How to get POST data

I am trying to send POST data to an Iron Router route from outside a meteor, but it does not work. The request body is empty.

I tried to output the request body to check if the data was present, but it is 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? Thanks.

+5
source share
2 answers

request.body empty because iron-router lacks the middleware responsible for retrieving url encoded data. This is a BUG , which we hope will be resolved in later versions. For now, you can simply add:

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

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

+8
source

Can you explain in datails. I applied Router.onBeforeAction but not working

0
source

Source: https://habr.com/ru/post/1206192/


All Articles