I’m continuing to dive into this issue with Meteor 1.3 and I found an NPM middleware package (body-parser-xml) that works with Picker. It requires body-parser. Here is the require for that:
var _bodyParser = require('body-parser');
require('body-parser-xml')(_bodyParser);`
and I confirmed that a) meteor instantiates body-parser and b.) body-parser now has the xml() function to process xml
Next, to execute the middleware, you need to tell Picker to do so during it’s route processing (at least I think):
Picker.middleware(_bodyParser.xml());
What is supposed to happen is the XML will be made available via the request.body. However, I never see it.
Here is the completed Picker route inside the Meteor.startup function:
Picker.route('/api/imports2', function(req, res, next) {
var _bodyParser = require('body-parser');
require('body-parser-xml')(_bodyParser);
Picker.middleware(_bodyParser.xml());
var _xml = req.body;
res.end(_xml);
});
Here is a curl example I’m sending:
curl -X POST -H "Content-Type: application/xml" -H "Accept: application/xml" -d '<run><log encoding="hexBinary">4142430A</log><result>0</result></duration></run>' http://localhost:3000/api/imports2/
All I receive is a request with an empty query object. No errors.
Using Charles, a web debugging proxy, all I see is the Meteor sockjs request with no indication of data.
Maybe it’s my CURL statement? Any advice?
I’m about to dump Meteor for this task and just write a node service. This should not be this hard…