Skip to content

Commit 6e651f4

Browse files
committed
updating docs, almost there
1 parent b1eb13e commit 6e651f4

File tree

3 files changed

+27
-22
lines changed

3 files changed

+27
-22
lines changed

README.md

+21-3
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,28 @@ Let's suppose you were running multiple http application servers, but you only w
2727

2828
### How to use node-http-proxy
2929

30-
#### usage 1:   creating a stand-alone proxy server
31-
32-
#### usage 2:   proxying existing http.Server requests
30+
####    proxying requests using http.Server
3331

32+
var sys = require('sys'),
33+
colors = require('colors')
34+
http = require('http');
35+
36+
var httpProxy = require('./lib/node-http-proxy').httpProxy;
37+
38+
http.createServer(function (req, res){
39+
var proxy = new httpProxy;
40+
proxy.init(req, res);
41+
sys.puts('proxying request to http://localhost:9000');
42+
proxy.proxyRequest('localhost', '9000', req, res);
43+
}).listen(8000);
44+
45+
http.createServer(function (req, res){
46+
res.writeHead(200, {'Content-Type': 'text/plain'});
47+
res.write('request successfully proxied!' + '\n' + JSON.stringify(req.headers, true, 2));
48+
res.end();
49+
}).listen(9000);
50+
51+
see the [demo](http://github.com/nodejitsu/node-http-proxy/blob/master/demo.js) for further examples.
3452
### Why doesn't node-http-proxy have more advanced features like x, y, or z?
3553

3654
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

demo.js

+3-16
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,11 @@
66
*
77
*/
88

9-
var vows = require('vows'),
10-
sys = require('sys'),
9+
var sys = require('sys'),
1110
colors = require('colors')
12-
assert = require('assert'),
1311
http = require('http');
1412

15-
var httpProxy = require('./lib/node-http-proxy');
16-
var testServers = {};
13+
var httpProxy = require('./lib/node-http-proxy').httpProxy;
1714

1815

1916
// ascii art from http://github.com/marak/asciimo
@@ -27,20 +24,10 @@ var welcome = '\
2724
sys.puts(welcome.rainbow.bold);
2825

2926

30-
// create regular http proxy server
31-
httpProxy.createServer('localhost', 9000, function (req, res){
32-
33-
sys.puts('any requests going to 8002 will get proxied to 9000');
34-
35-
}).listen('localhost', 8002);
36-
37-
sys.puts('http proxy server'.blue + ' started '.green.bold + 'on port '.blue + '8000'.yellow);
38-
39-
4027

4128
// create regular http proxy server
4229
http.createServer(function (req, res){
43-
var proxy = new httpProxy.httpProxy;
30+
var proxy = new httpProxy;
4431
proxy.init(req, res);
4532
sys.puts('proxying request to http://localhost:9000');
4633
proxy.proxyRequest('localhost', '9000', req, res);

test/node-http-proxy-test.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ var vows = require('vows'),
1313

1414
require.paths.unshift(require('path').join(__dirname, '../lib/'));
1515

16-
var httpProxy = require('node-http-proxy');
16+
var httpProxy = require('node-http-proxy').httpProxy;
1717
var testServers = {};
1818

1919
//
@@ -89,7 +89,7 @@ vows.describe('node-proxy').addBatch({
8989
"When an incoming request is proxied to the helloNode server" : {
9090
"with no latency" : {
9191
topic: function () {
92-
var proxy = new httpProxy.httpProxy;
92+
var proxy = new httpProxy;
9393
startTest(proxy, 8082);
9494
proxy.emitter.addListener('end', this.callback);
9595

@@ -106,7 +106,7 @@ vows.describe('node-proxy').addBatch({
106106
},
107107
"with latency": {
108108
topic: function () {
109-
var proxy = new httpProxy.httpProxy;
109+
var proxy = new httpProxy;
110110
startTestWithLatency(proxy, 8083);
111111
proxy.emitter.addListener('end', this.callback);
112112

0 commit comments

Comments
 (0)