I already tried server-routing with Iron Router, but that doesn't work. Then I discovered WebApp, which seems like it's supposed to handle this.
But when I inspect the req object:
WebApp.connectHandlers.use("/api/add", function( req, res, next ) {
console.log( req );
res.writeHead(200);
res.end("Hello world from: " + Meteor.release);
});
I don't see any of my POST form-data. There's no body property, and I don't see the data itself anywhere under any other property.
How can I access this data? I'm going crazy trying to figure out something I thought would be relatively simple...
I already tried server-routing with Iron Router, but that doesn't work. Then I discovered WebApp, which seems like it's supposed to handle this.
But when I inspect the req object:
WebApp.connectHandlers.use("/api/add", function( req, res, next ) {
console.log( req );
res.writeHead(200);
res.end("Hello world from: " + Meteor.release);
});
I don't see any of my POST form-data. There's no body property, and I don't see the data itself anywhere under any other property.
How can I access this data? I'm going crazy trying to figure out something I thought would be relatively simple...
Share Improve this question asked Sep 21, 2015 at 22:26 m52gom52go 3431 gold badge3 silver badges14 bronze badges1 Answer
Reset to default 10Yeah, I had the same issue. With connect, the post body isn't automatically in the request object. You can use middleware like this https://stackoverflow./a/24122700/5203563 or get it yourself like this:
WebApp.connectHandlers.use("/api/add", function( req, res, next ) {
var body = "";
req.on('data', Meteor.bindEnvironment(function (data) {
body += data;
}));
req.on('end', Meteor.bindEnvironment(function () {
console.log(body);
res.writeHead(200);
res.end("Hello world from: " + Meteor.release);
}));
});