Socket hangup while posting request to Node-http-proxy Node.js Socket hangup while posting request to Node-http-proxy Node.js express express

Socket hangup while posting request to Node-http-proxy Node.js


Use a callback to listen for the error:

proxy.web(req, res, { target: 'http://mytarget.com:8080' }, function(e) { ... });

from https://github.com/nodejitsu/node-http-proxy


I think the issue comes from the order of middleware. Using bodyParser before httpProxy will break the requests with JSON body, so httpProxy should be used before bodyParser.

You may want to check this for more info about bodyParser.


I found the solution to this problem with the help of this issuehttps://github.com/nodejitsu/node-http-proxy/issues/180#issuecomment-12244852

the solution is to use middleware for proxy before using the bodyparser

code sample

 // use middleware first app.post('/solr/*',function(req, res) {  console.log('POST REQUEST')  //res.end();   proxy.web(req, res, {     target: 'http://' + proxyOptions.host + ':' + proxyOptions.port   });})app.use(logger('dev'));// use bodyparser after thatapp.use(bodyParser.json());app.use(bodyParser.urlencoded({ extended: false }));