Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a solution that lets Node.js act as an HTTP reverse proxy?

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?

like image 538
Igor Zinov'yev Avatar asked Jun 21 '26 13:06

Igor Zinov'yev


2 Answers

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.

like image 65
Phillip B Oldham Avatar answered Jun 23 '26 05:06

Phillip B Oldham


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);</code></pre>
like image 35
JimBastard Avatar answered Jun 23 '26 04:06

JimBastard



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!