I want to do some vhost-jiggery-pokery with node-proxy
. Consider that I have a slave script up and running, which listens on a unix-socket: /tmp/node-http/cubixcraft.de
When I want to load it into my node-proxy with the following script it simply doesn't work. The webpage doesn't respond.
var fs = require("fs"),
httpProxy = require("http-proxy");
var options = {
hostnameOnly: true,
router: {
"cubixcraft.de": "/tmp/node-http/cubixcraft.de"
}
};
var proxyServer = httpProxy.createServer(options).listen(80);
When I use normal ports instead of socket-paths everything works just fine. I even fired a get request on the socket-path that successfully finished. The path really works. There seems to be something wrong with the node-proxy.
Is anybody experiencing the same problems?
I wanted to do something similar recently, but according to the open github issue here http://github.com/nodejitsu/node-http-proxy/issues/104 it is not possible yet.
As zi42 pointed out this behaviour is a bug. I digged into the code and found out, that they don't care about sockets. There is not a single line that deals with socketsPath
s.
Since nobody has respond to the issue in a long time I fixed it myself. You can find the result here. This is a wrapper-module that includes socketPath
's. I will make a pull request, so that socketPath
s will work by default soon.
The following example shows how to use it. I assume, that you have a HTTP-server listening on the socket "/tmp/node-http/myserver.com".
var httpProxy = require("./fixed-http-proxy.js"); // This assumes that you have my .js in your cwd and http-proxy installed as a module (npm install http-proxy)
console.log(httpProxy);
var options = {
hostnameOnly: true,
router: {
"myserver.com": "/tmp/node-http/myserver.com" // Sockets are determined by a leading slash
}
};
var proxyServer = httpProxy.createServer(options).listen(80); // myserver.com:80 now internally proxies to /tmp/node-http/myserver.com