diff --git a/README.md b/README.md index d6771b8..2bf40b6 100644 --- a/README.md +++ b/README.md @@ -27,10 +27,28 @@ Let's suppose you were running multiple http application servers, but you only w ### How to use node-http-proxy -#### usage 1:   creating a stand-alone proxy server - -#### usage 2:   proxying existing http.Server requests +####    proxying requests using http.Server + var sys = require('sys'), + colors = require('colors') + http = require('http'); + + var httpProxy = require('./lib/node-http-proxy').httpProxy; + + http.createServer(function (req, res){ + var proxy = new httpProxy; + proxy.init(req, res); + sys.puts('proxying request to http://localhost:9000'); + 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); + +see the [demo](http://github.com/nodejitsu/node-http-proxy/blob/master/demo.js) for further examples. ### Why doesn't node-http-proxy have more advanced features like x, y, or z? if you have a suggestion for a feature currently not supported, feel free to open a [support issue](https://github.com/nodejitsu/node-http-proxy/issues). node-http-proxy is designed to just proxy https request from one server to another, but we will be soon releasing many other complimentary projects that can be used in conjunction with node-http-proxy \ No newline at end of file diff --git a/demo.js b/demo.js index 8358758..f9b9d54 100644 --- a/demo.js +++ b/demo.js @@ -6,14 +6,11 @@ * */ -var vows = require('vows'), - sys = require('sys'), +var sys = require('sys'), colors = require('colors') - assert = require('assert'), http = require('http'); -var httpProxy = require('./lib/node-http-proxy'); -var testServers = {}; +var httpProxy = require('./lib/node-http-proxy').httpProxy; // ascii art from http://github.com/marak/asciimo @@ -27,20 +24,10 @@ var welcome = '\ sys.puts(welcome.rainbow.bold); -// create regular http proxy server -httpProxy.createServer('localhost', 9000, function (req, res){ - - sys.puts('any requests going to 8002 will get proxied to 9000'); - -}).listen('localhost', 8002); - -sys.puts('http proxy server'.blue + ' started '.green.bold + 'on port '.blue + '8000'.yellow); - - // create regular http proxy server http.createServer(function (req, res){ - var proxy = new httpProxy.httpProxy; + var proxy = new httpProxy; proxy.init(req, res); sys.puts('proxying request to http://localhost:9000'); proxy.proxyRequest('localhost', '9000', req, res); diff --git a/test/node-http-proxy-test.js b/test/node-http-proxy-test.js index 74c20fa..5d11582 100644 --- a/test/node-http-proxy-test.js +++ b/test/node-http-proxy-test.js @@ -13,7 +13,7 @@ var vows = require('vows'), require.paths.unshift(require('path').join(__dirname, '../lib/')); -var httpProxy = require('node-http-proxy'); +var httpProxy = require('node-http-proxy').httpProxy; var testServers = {}; // @@ -89,7 +89,7 @@ vows.describe('node-proxy').addBatch({ "When an incoming request is proxied to the helloNode server" : { "with no latency" : { topic: function () { - var proxy = new httpProxy.httpProxy; + var proxy = new httpProxy; startTest(proxy, 8082); proxy.emitter.addListener('end', this.callback); @@ -106,7 +106,7 @@ vows.describe('node-proxy').addBatch({ }, "with latency": { topic: function () { - var proxy = new httpProxy.httpProxy; + var proxy = new httpProxy; startTestWithLatency(proxy, 8083); proxy.emitter.addListener('end', this.callback);