Skip to content

Commit

Permalink
updating docs, almost there
Browse files Browse the repository at this point in the history
  • Loading branch information
Marak committed Jul 27, 2010
1 parent b1eb13e commit 6e651f4
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 22 deletions.
24 changes: 21 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
19 changes: 3 additions & 16 deletions demo.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions test/node-http-proxy-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {};

//
Expand Down Expand Up @@ -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);

Expand All @@ -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);

Expand Down

0 comments on commit 6e651f4

Please sign in to comment.