Reputation: 29169
I have written a node.js proxy server ( its here on github )
The problem is that the connect.bodyParser doesn't work very well. For this probject I've written my own bodyParser (see the file 'server'), but now I was testing again with connect.bodyParser. In short, I have now something like:
app.use(connect.bodyParser())
.use(connect.query())
.use(serveFromDB)
.use(actAsProxyServer)
.use(cacheContent)
.use(function(err, req, res, next) {
console.log("ERROR: " + JSON.stringify(err)) ;
console.log("URL=" + req.url) ;
console.dir(req.headers) ;
res.setHeader('Content-Type', 'application/json');
res.end(JSON.stringify(err));
}) ;
Here is output from the error function:
ERROR: {"status":400}
URL=/Client/rest/cache/Clients/user123/X7X1
{ host: 'localhost:8000',
connection: 'keep-alive',
'x-requested-with': 'XMLHttpRequest',
'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_5) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.64 Safari/537.11',
'content-type': 'application/json; charset=utf-8',
accept: 'application/json, text/javascript, */*; q=0.01',
referer: 'http://localhost:8000/Client/index.jsp?cache=true',
'accept-encoding': 'gzip,deflate,sdch',
'accept-language': 'en-US,en;q=0.8',
'accept-charset': 'ISO-8859-1,utf-8;q=0.7,*;q=0.3',
cookie: 'JSESSIONID=d1cbd411e30bcfb759e29585ee23' }
The only thing this GET request does is calling that url (without any parameters)
Any suggestions why the bodyParser throws an error on this GET request ?
Cheers
UPDATE: I found the code of bodyParser here. In json.js it finaly throws the error because its trying to turn an empty string (because there is no body) into json. I though bodyParser is only for POST request!!
UPDATE1: found the problem: https://github.com/documentcloud/backbone/pull/267 I think I have a content-type in my GET request
Upvotes: 0
Views: 537