@@ -12,14 +12,53 @@ var vows = require('vows'),
12
12
assert = require ( 'assert' ) ,
13
13
http = require ( 'http' ) ;
14
14
15
- require . paths . unshift ( require ( 'path' ) . join ( __dirname , '../lib/' ) ) ;
15
+ var NodeProxy = require ( './lib/node-proxy' ) . NodeProxy ;
16
+ var testServers = { } ;
16
17
17
18
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 )
19
29
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;
20
61
21
- var NodeProxy = require ( './lib/node-proxy' ) . NodeProxy ;
22
- var testServers = { } ;
23
62
24
63
//
25
64
// Simple 'hello world' response for test purposes
@@ -30,19 +69,6 @@ var helloWorld = function(req, res) {
30
69
res.end();
31
70
};
32
71
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
- } ;
46
72
47
73
//
48
74
// Creates the reverse proxy server with a specified latency
@@ -90,6 +116,20 @@ var startTestWithLatency = function (proxy, port) {
90
116
testServers.latency.push(startTargetServer(port));
91
117
};
92
118
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
+
93
133
vows.describe('node-proxy').addBatch({
94
134
"When an incoming request is proxied to the helloNode server" : {
95
135
"with no latency" : {
@@ -127,4 +167,6 @@ vows.describe('node-proxy').addBatch({
127
167
}
128
168
}
129
169
}
130
- } ) . export ( module ) ;
170
+ }).export(module);
171
+
172
+ */
0 commit comments