indexzero
2/9/2012 - 9:44 PM

A simple outbound proxy server with node-http-proxy

A simple outbound proxy server with node-http-proxy

var httpProxy = require('http-proxy');

var server = httpProxy.createServer(function (req, res, proxy) {
  //
  // Inspect the request
  //
  console.dir(req);
  
  //
  // Proxy to the Remote Location
  //
  proxy.proxyRequest(req, res, {
    host: 'path-to-remote-api-endpoint.com',
    port: 80
  });
});

//
// Start the proxy server. You should connect to
// http://localhost:3000/
//
server.listen(3000);