Skip to content

Commit b622702

Browse files
committed
updated demo
1 parent 2f265a2 commit b622702

File tree

2 files changed

+11
-12
lines changed

2 files changed

+11
-12
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ see the [demo](http://github.com/nodejitsu/node-http-proxy/blob/master/demo.js)
6363
res.write('request successfully proxied!' + '\n' + JSON.stringify(req.headers, true, 2));
6464
res.end();
6565
}).listen(9000);
66+
6667
</pre>
6768

6869
### Why doesn't node-http-proxy have more advanced features like x, y, or z?

demo.js

+10-12
Original file line numberDiff line numberDiff line change
@@ -39,33 +39,31 @@ var welcome = '\
3939
# # # # # # # # #### # # # \n';
4040
sys.puts(welcome.rainbow.bold);
4141

42-
// create regular http proxy server
42+
43+
/****** basic http proxy server ******/
4344
httpProxy.createServer('localhost', 9000).listen(8000);
4445
sys.puts('http proxy server'.blue + ' started '.green.bold + 'on port '.blue + '8000'.yellow);
4546

46-
// http proxy server with latency
47+
/****** http proxy server with latency******/
4748
httpProxy.createServer(function (req, res, proxy){
4849
setTimeout(function(){
4950
proxy.proxyRequest('localhost', 9000, req, res);
5051
}, 200)
5152
}).listen(8001);
5253
sys.puts('http proxy server '.blue + 'started '.green.bold + 'on port '.blue + '8001 '.yellow + 'with latency'.magenta.underline );
5354

54-
55-
// http proxy server with latency
55+
/****** http server with proxyRequest handler and latency******/
5656
http.createServer(function (req, res){
57+
var proxy = new httpProxy.HttpProxy;
58+
proxy.watch(req, res);
59+
5760
setTimeout(function(){
58-
59-
var proxy = new httpProxy.HttpProxy;
60-
proxy.watch(req, res);
6161
proxy.proxyRequest('localhost', 9000, req, res);
62-
63-
}, 200)
62+
}, 200);
6463
}).listen(8002);
65-
sys.puts('http proxy server '.blue + 'started '.green.bold + 'on port '.blue + '8002 '.yellow + 'with latency'.magenta.underline );
66-
64+
sys.puts('http server '.blue + 'started '.green.bold + 'on port '.blue + '8002 '.yellow + 'with proxyRequest handler'.cyan.underline + ' and latency'.magenta);
6765

68-
// create regular http server
66+
/****** regular http server ******/
6967
http.createServer(function (req, res){
7068
res.writeHead(200, {'Content-Type': 'text/plain'});
7169
res.write('request successfully proxied: ' + req.url +'\n' + JSON.stringify(req.headers, true, 2));

0 commit comments

Comments
 (0)