views:

591

answers:

2

Our company has a project that right now uses nginx as a reverse proxy for serving static content and supporting comet connections. We use long polling connections to get rid of constant refresh requests and let users get updates immediately.

Now, I know there is a lot of code already written for Node.js, but is there a solution that lets Node.js act as a reverse proxy for serving static content as nginx does? Or maybe there is a framework that allows to quickly develop such a layer using Node.js?

+3  A: 

dogproxy might be able to help you, if not as a full solution then possibly as the building blocks for one.

However, you might wish to reconsider keeping nginx for serving static content -- it is specifically designed and tuned for this particular task. You would be adding a lot of overhead in using node.js to serve static content - much like using PHP to serve static files.

digitala
Thanks for the good advice!
Igor Zinov'yev
+1  A: 

node-http-proxy sounds like what you want

var sys = require('sys'),
      http = require('http'),
      httpProxy = require('http-proxy').httpProxy;

  http.createServer(function (req, res){
    var proxy = new httpProxy;
    proxy.init(req, res);
    proxy.proxyRequest('localhost', '9000', req, res);
  }).listen(8000);

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