I’m playing around with Journey on node and I only realized that the router is interpreting JSON requests objects as the value of the key that has an empty value:
In other words, when i post to the server a JSON object I get the following:
http://127.0.0.1:3000/> post /events
... {url : "test"}
HTTP/1.1 200 OK
Date: Tue, 21 Feb 2012 00:42:38 GMT
Server: journey/0.4.0
Content-Type: application/json;charset=utf-8
Content-Length: 67
Connection: keep-alive
{
event: {
_id: '10tPxx',
resource: 'Event',
{url : "test"}: ''
}
}
As you can see the whole object is being considered as a string.
Here’s my Journey related code:
exports.createRouter = function(resource){
var router = new (journey.Router)({
api: 'basic'
});
router.path(/\/events/, function(){
....
this.post().bind(function(res, event){
console.log(event);
resource.create(event, function(err, result){
if(err){
return res.send(500, {}, {error: err.error});
}
res.send(200, {}, { event: result});
});
});
...
});
return router;
};
The printout of the console is:
{ '{url : "test"}': '' }
What could possibly be wrong?
It looks like the json is getting parsed using querystring.parse instead of JSON.parse.
Make sure that you are properly sending a ‘content-type’ header with ‘application/json’.