nodejitsu/node-http-proxy — Issue #153: issue with express and http-proxy
Author: ramv
Created: 2011-11-10 07:43:32+00:00
State: open

cannot get the following code to work

var util = require('util'),
express = require('express'),
httpProxy = require('http-proxy');

var app = express.createServer(),
proxy = new httpProxy.HttpProxy({
target: {
host: '127.0.0.1'
, port: '7070'
}
});

app.configure(function() {
app.use(express.static(__dirname));
app.use(express.bodyParser());
app.use(express.cookieParser());
app.use(express.session({secret: 'f7cd7374c2851fb727582bf'}));
});

// Proxy BOSH request to XMPP server

app.all('/http-bind', function(req, res) {
util.puts('Request successfully proxied: ' + req.url);
util.puts(JSON.stringify(req.headers, true, 2));
proxy.proxyRequest(req, res);
});

app.listen(8080); // XMPP
util.puts("Server running at http://0.0.0.0:8080/ in " + app.set("env") + " mode.");

The culprit appears to be the following line
app.use(express.static(__dirname));

When this line is commented out, the proxy works correctly, but when the line is not commented out, I get a 500 error

An error has occurred: {"stack":"Error: socket hang up
at Socket. (http.js:1290:45)
at Socket.emit (events.js:64:17)
at Array.0 (net.js:837:12)
at EventEmitter._tickCallback (node.js:126:26)","message":"socket hang up"}