Skip to content

Commit 2fb5ffb

Browse files
committed
started to flesh out simple demo based on tests
1 parent d490b50 commit 2fb5ffb

File tree

3 files changed

+60
-19
lines changed

3 files changed

+60
-19
lines changed

demo.js

+60-18
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,53 @@ var vows = require('vows'),
1212
assert = require('assert'),
1313
http = require('http');
1414

15-
require.paths.unshift(require('path').join(__dirname, '../lib/'));
15+
var NodeProxy = require('./lib/node-proxy').NodeProxy;
16+
var testServers = {};
1617

1718

18-
sys.puts('node-http-proxy has started!'.rainbow);
19+
// regular http server
20+
http.createServer(function (req, res){
21+
// Initialize the nodeProxy and start proxying the request
22+
var proxy = new (NodeProxy);
23+
proxy.init(req, res);
24+
// lets proxy the request to another service
25+
proxy.proxyRequest('localhost', '8081', req, res);
26+
27+
}).listen(8080);
28+
sys.puts('started a http server on port 8080'.green)
1929

30+
// http server with latency
31+
http.createServer(function (req, res){
32+
// Initialize the nodeProxy and start proxying the request
33+
var proxy = new (NodeProxy);
34+
proxy.init(req, res);
35+
36+
// lets proxy the request to another service
37+
setTimeout(function(){
38+
proxy.proxyRequest('localhost', '8090', req, res);
39+
}, 200)
40+
41+
}).listen(8081);
42+
sys.puts('started a http server with latency on port 8081'.green)
43+
44+
45+
46+
http.createServer(function (req, res){
47+
res.writeHead(200, {'Content-Type': 'text/plain'});
48+
res.write('foo');
49+
res.end();
50+
}).listen(8090);
51+
sys.puts('started another http server on port 8090'.green)
52+
53+
54+
sys.puts('to test the proxy server, request http://localhost:8080/ in your browser.');
55+
sys.puts('your request will proxy to the server running on port 8081');
56+
57+
58+
/*
59+
60+
return;
2061
21-
var NodeProxy = require('./lib/node-proxy').NodeProxy;
22-
var testServers = {};
2362
2463
//
2564
// Simple 'hello world' response for test purposes
@@ -30,19 +69,6 @@ var helloWorld = function(req, res) {
3069
res.end();
3170
};
3271
33-
//
34-
// Creates the reverse proxy server
35-
//
36-
var startProxyServer = function (server, port, proxy) {
37-
var proxyServer = http.createServer(function (req, res){
38-
// Initialize the nodeProxy and start proxying the request
39-
proxy.init(req, res);
40-
proxy.proxyRequest(server, port, req, res);
41-
});
42-
43-
proxyServer.listen(8080);
44-
return proxyServer;
45-
};
4672
4773
//
4874
// Creates the reverse proxy server with a specified latency
@@ -90,6 +116,20 @@ var startTestWithLatency = function (proxy, port) {
90116
testServers.latency.push(startTargetServer(port));
91117
};
92118
119+
120+
sys.puts('node-http-proxy has started!'.green);
121+
122+
// start the http-proxy
123+
var proxy = new (NodeProxy);
124+
startTest(proxy, 8082);
125+
126+
127+
// start a second http server (which we will reverse proxy our requests to)
128+
129+
130+
return;
131+
132+
93133
vows.describe('node-proxy').addBatch({
94134
"When an incoming request is proxied to the helloNode server" : {
95135
"with no latency" : {
@@ -127,4 +167,6 @@ vows.describe('node-proxy').addBatch({
127167
}
128168
}
129169
}
130-
}).export(module);
170+
}).export(module);
171+
172+
*/

lib/asciimo.js

Whitespace-only changes.

vendor/asciimo

-1
This file was deleted.

0 commit comments

Comments
 (0)