POST-data with meteorhacks:picker


#1

Hi

Trying to break away from iron:router but I’m struggling with some basic concepts.

I’m trying to recieve POST-data from Mailgun (incoming mail), this is my code:

var bodyParser = Meteor.npmRequire('body-parser'); 
Picker.middleware(bodyParser.urlencoded({ extended: false }));
Picker.middleware(bodyParser.json());

var post = Picker.filter(function(req, res) {
  return req.method == "POST";
});

post.route('/post', function(params, req, res, next) {
  console.log(params);   // { query: {} }
  console.log(req.data); // undefined
  console.log(req.body); // {}
  res.end();
});

How can I solve this?

If I make a HTTP.post on my own with data instead of params it works, but I can’t control what Mailgun sends me


#2

It works try doing this. It works.

curl -d "aa=10&bb-20" http://localhost:3000/post

Params is for when you are using express like paths for the route and to get query params.


#3

Thanks @arunoda, that works. I’ll ask Mailgun how they are sending their data. Cheers


#4

The HTTP Post will be encoded as application/x-www-form-urlencoded for most messages, and multipart/form-data if there’s an attachment included.

This is the reply I got, do I have to add anything else?


#5

They seems like sending a URL encoded message. try to inspect what they send with a service like this: http://requestb.in/


#6

Were you able to find a solution to this @benjick? It seems like I need to have Meteor wait for a stream to finish before the full results are ready to use. I’m certainly seeing the same issue you pointed out.


#7

bodyParser does not handle form-data, try something like https://www.npmjs.com/package/connect-multiparty#readme


#8

@benjick

Were you able to get Mailgun incoming working?

I wonder whether Meteor 1.3 makes this easier now that npm packages are easier to install (but on the flipside, 1.3 is so new that there are still limited tutorials for noobs like me!)


#9

did you solve this in the end? how you parsing the multipart once you receiving it with Picker?


#10

This worked for me:

Picker.route('/yourapi', function(params, req, res, next) {
  let body = ''
  req.on('data', Meteor.bindEnvironment((data) => {
    body += data;
  })).on('end', function() {
      console.log(body)
      // do something here
     res.end('api result');
  })
})

#11

This is sort of working, it’s giving me what looks like a buffer or base64 string or something. But it’s not easily parsible