Commit b6227021 authored by Marak Squires's avatar Marak Squires

updated demo

parent 2f265a23
...@@ -63,6 +63,7 @@ see the [demo](http://github.com/nodejitsu/node-http-proxy/blob/master/demo.js) ...@@ -63,6 +63,7 @@ see the [demo](http://github.com/nodejitsu/node-http-proxy/blob/master/demo.js)
res.write('request successfully proxied!' + '\n' + JSON.stringify(req.headers, true, 2)); res.write('request successfully proxied!' + '\n' + JSON.stringify(req.headers, true, 2));
res.end(); res.end();
}).listen(9000); }).listen(9000);
</pre> </pre>
### Why doesn't node-http-proxy have more advanced features like x, y, or z? ### Why doesn't node-http-proxy have more advanced features like x, y, or z?
......
...@@ -39,11 +39,12 @@ var welcome = '\ ...@@ -39,11 +39,12 @@ var welcome = '\
# # # # # # # # #### # # # \n'; # # # # # # # # #### # # # \n';
sys.puts(welcome.rainbow.bold); sys.puts(welcome.rainbow.bold);
// create regular http proxy server
/****** basic http proxy server ******/
httpProxy.createServer('localhost', 9000).listen(8000); httpProxy.createServer('localhost', 9000).listen(8000);
sys.puts('http proxy server'.blue + ' started '.green.bold + 'on port '.blue + '8000'.yellow); sys.puts('http proxy server'.blue + ' started '.green.bold + 'on port '.blue + '8000'.yellow);
// http proxy server with latency /****** http proxy server with latency******/
httpProxy.createServer(function (req, res, proxy){ httpProxy.createServer(function (req, res, proxy){
setTimeout(function(){ setTimeout(function(){
proxy.proxyRequest('localhost', 9000, req, res); proxy.proxyRequest('localhost', 9000, req, res);
...@@ -51,21 +52,18 @@ httpProxy.createServer(function (req, res, proxy){ ...@@ -51,21 +52,18 @@ httpProxy.createServer(function (req, res, proxy){
}).listen(8001); }).listen(8001);
sys.puts('http proxy server '.blue + 'started '.green.bold + 'on port '.blue + '8001 '.yellow + 'with latency'.magenta.underline ); sys.puts('http proxy server '.blue + 'started '.green.bold + 'on port '.blue + '8001 '.yellow + 'with latency'.magenta.underline );
/****** http server with proxyRequest handler and latency******/
// http proxy server with latency
http.createServer(function (req, res){ http.createServer(function (req, res){
var proxy = new httpProxy.HttpProxy;
proxy.watch(req, res);
setTimeout(function(){ setTimeout(function(){
var proxy = new httpProxy.HttpProxy;
proxy.watch(req, res);
proxy.proxyRequest('localhost', 9000, req, res); proxy.proxyRequest('localhost', 9000, req, res);
}, 200);
}, 200)
}).listen(8002); }).listen(8002);
sys.puts('http proxy server '.blue + 'started '.green.bold + 'on port '.blue + '8002 '.yellow + 'with latency'.magenta.underline ); sys.puts('http server '.blue + 'started '.green.bold + 'on port '.blue + '8002 '.yellow + 'with proxyRequest handler'.cyan.underline + ' and latency'.magenta);
// create regular http server /****** regular http server ******/
http.createServer(function (req, res){ http.createServer(function (req, res){
res.writeHead(200, {'Content-Type': 'text/plain'}); res.writeHead(200, {'Content-Type': 'text/plain'});
res.write('request successfully proxied: ' + req.url +'\n' + JSON.stringify(req.headers, true, 2)); res.write('request successfully proxied: ' + req.url +'\n' + JSON.stringify(req.headers, true, 2));
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment