Wynn Netherland changelog.com/posts

node-http-proxy: Reverse proxy for Node.js

Reverse proxies are a pretty standard part of any modern web stack. If you’re dabbling in Node.js and need one to provide caching, added security, or load balancing, you should checkout node-http-proxy from Marak and Charlie at nodejitsu.

To install via npm

npm install http-proxy

A quick example:

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);

[Source on GitHub]


Discussion

Sign in or Join to comment or subscribe

Player art
  0:00 / 0:00