Use of server depending on the http host
AndreasMadsen opened this issue · comments
The bigest problem I face with node.js every day is that it's very difficult to have more that one domain on the same server, without mixing the server.js files.
I believe we could adapt cluster to mangage this issue, the API cloud be very simple, something like:
cluster('./app')
.use(cluster.cli())
.httpListen("example.com", 80);
However I am not a network expert, so I'm hoping that someone cloud give me some insite or perhaps make a pull request.
you can already listen on a domain, or are you looking for "virtual host"-like functionality?
Yes I'm looking for at "virtual host" system.
ah, well I would suggest (if you want to stick with node tools) to use cluster+node-http-proxy, or alternatively use Connect's vhost()
middleware+cluster which essentially just routes by domain, slightly different benefits from each
I have reviewed both of them.
Connect-vhost
seams to make the http routing very transparent, however it do not support independent process since you have to add thehttpServer
instance directly to theconnect-core
.Node-http-proxy
do support independent process, but are sending thehost-address
by usinghttp-headers
with makes it less transparent.
Cluster seams to manage the host-address
transparently issue by using the net.listenFD
method. Do you know if this also can be used in a socket-connection
where a part of the incoming data (http-host-header) already have been send by the client and read by a 'http-proxy-server'.
I have created a plugin to cluster there use the node-http-proxy
module. It can be found on: https://github.com/AndreasMadsen/cluster-vhost
I will make a README pull request when I have documented the configuration file.
awesome :)