This is actually surprisingly simple due to great work done by nodejitsu and also by the connect team. And I have largely copied the content from the links at the bottom of the page:

So with http proxy you can use it as follows:


npm install http-proxy

-- app.js ---

var http = require('http'),
httpProxy = require('http-proxy');
//
// Create your proxy server
//
var options = {
hostnameOnly: true,
router: {
'foo.com': '127.0.0.1:8001',
'bar.com': '127.0.0.1:8002'
}
}
httpProxy.createServer(options).listen(80);

in terminal run
nohup nodemon app.js & //will keep it running

-- foo.js --

var http = require('http');
http.createServer(function (req, res) {
res.writeHead(200, { 'Content-Type': 'text/plain' });
res.write('request successfully proxied 8001!' + '\n' + JSON.stringify(req.headers, true, 2));
res.end();
}).listen(8001);

in terminal run nodemon foo.js
-- bar.js --

var http = require('http');
http.createServer(function (req, res) {
res.writeHead(200, { 'Content-Type': 'text/plain' });
res.write('request successfully proxied 8001!' + '\n' + JSON.stringify(req.headers, true, 2));
res.end();
}).listen(8002);

in terminal run nodemon bar.js

finally edit your /private/etc/hosts file and add:

127.0.0.1 foo.com
127.0.0.1 bar.com

browse to bar.com and foo.com to see that both apps are running.

more info here
nodejitsu http proxy

The vhosts from connect is also really nice:
you can see a really good example of this in action here:

vhosts example

Sorry, the comment form is closed at this time.

   
© 2012 Craig Brookes Suffusion theme by Sayontan Sinha