Skip to content

Commit

Permalink
[tests] Added a test case for run all the examples
Browse files Browse the repository at this point in the history
 * I changed all the ports across examples to be different and can run at same time
  • Loading branch information
cronopio committed Dec 18, 2013
1 parent c82ff2c commit bc236d7
Show file tree
Hide file tree
Showing 19 changed files with 144 additions and 72 deletions.
2 changes: 1 addition & 1 deletion examples/balancer/simple-balancer-with-websockets.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,5 +80,5 @@ server.on('upgrade', function (req, socket, head) {
nextProxy().ws(req, socket, head);
});

server.listen(8080);
server.listen(8001);

2 changes: 1 addition & 1 deletion examples/balancer/simple-balancer.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,6 @@ http.createServer(function (req, res) {
// ...and then the server you just used becomes the last item in the list.
//
addresses.push(target);
}).listen(8000);
}).listen(8021);

// Rinse; repeat; enjoy.
10 changes: 5 additions & 5 deletions examples/http/basic-proxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ util.puts(welcome.rainbow.bold);
// Basic Http Proxy Server
//
httpProxy.createServer({
target:'http://localhost:9000'
}).listen(8000);
target:'http://localhost:9003'
}).listen(8003);

//
// Target Http Server
Expand All @@ -54,7 +54,7 @@ http.createServer(function (req, res) {
res.writeHead(200, { 'Content-Type': 'text/plain' });
res.write('request successfully proxied to: ' + req.url + '\n' + JSON.stringify(req.headers, true, 2));
res.end();
}).listen(9000);
}).listen(9003);

util.puts('http proxy server'.blue + ' started '.green.bold + 'on port '.blue + '8000'.yellow);
util.puts('http server '.blue + 'started '.green.bold + 'on port '.blue + '9000 '.yellow);
util.puts('http proxy server'.blue + ' started '.green.bold + 'on port '.blue + '8003'.yellow);
util.puts('http server '.blue + 'started '.green.bold + 'on port '.blue + '9003 '.yellow);
10 changes: 5 additions & 5 deletions examples/http/concurrent-proxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ var util = require('util'),
// Basic Http Proxy Server
//
httpProxy.createServer({
target:'http://localhost:9000'
}).listen(8000);
target:'http://localhost:9004'
}).listen(8004);

//
// Target Http Server
Expand Down Expand Up @@ -62,7 +62,7 @@ http.createServer(function (req, res) {
connections.shift()();
}
}
}).listen(9000);
}).listen(9004);

util.puts('http proxy server'.blue + ' started '.green.bold + 'on port '.blue + '8000'.yellow);
util.puts('http server '.blue + 'started '.green.bold + 'on port '.blue + '9000 '.yellow);
util.puts('http proxy server'.blue + ' started '.green.bold + 'on port '.blue + '8004'.yellow);
util.puts('http server '.blue + 'started '.green.bold + 'on port '.blue + '9004 '.yellow);
6 changes: 3 additions & 3 deletions examples/http/custom-proxy-error.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@ var util = require('util'),
// Http Proxy Server with bad target
//
var proxy = httpProxy.createServer({
target:'http://localhost:9000'
target:'http://localhost:9005'
});

//
// Tell the proxy to listen on port 8000
//
proxy.listen(8000);
proxy.listen(8005);

//
// Listen for the `error` event on `proxy`.
Expand All @@ -52,4 +52,4 @@ proxy.on('error', function (err, req, res) {
});


util.puts('http proxy server '.blue + 'started '.green.bold + 'on port '.blue + '8000 '.yellow + 'with custom error message'.magenta.underline);
util.puts('http proxy server '.blue + 'started '.green.bold + 'on port '.blue + '8005 '.yellow + 'with custom error message'.magenta.underline);
16 changes: 8 additions & 8 deletions examples/http/forward-and-target-proxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,14 @@ var util = require('util'),
//
httpProxy.createServer({
target: {
port: 9000,
port: 9006,
host: 'localhost'
},
forward: {
port: 9001,
port: 9007,
host: 'localhost'
}
}).listen(8000);
}).listen(8006);

//
// Target Http Server
Expand All @@ -50,7 +50,7 @@ http.createServer(function (req, res) {
res.writeHead(200, { 'Content-Type': 'text/plain' });
res.write('request successfully proxied to: ' + req.url + '\n' + JSON.stringify(req.headers, true, 2));
res.end();
}).listen(9000);
}).listen(9006);

//
// Target Http Forwarding Server
Expand All @@ -60,8 +60,8 @@ http.createServer(function (req, res) {
res.writeHead(200, { 'Content-Type': 'text/plain' });
res.write('request successfully forwarded to: ' + req.url + '\n' + JSON.stringify(req.headers, true, 2));
res.end();
}).listen(9001);
}).listen(9007);

util.puts('http proxy server '.blue + 'started '.green.bold + 'on port '.blue + '8000 '.yellow + 'with forward proxy'.magenta.underline);
util.puts('http server '.blue + 'started '.green.bold + 'on port '.blue + '9000 '.yellow);
util.puts('http forward server '.blue + 'started '.green.bold + 'on port '.blue + '9001 '.yellow);
util.puts('http proxy server '.blue + 'started '.green.bold + 'on port '.blue + '8006 '.yellow + 'with forward proxy'.magenta.underline);
util.puts('http server '.blue + 'started '.green.bold + 'on port '.blue + '9006 '.yellow);
util.puts('http forward server '.blue + 'started '.green.bold + 'on port '.blue + '9007 '.yellow);
10 changes: 5 additions & 5 deletions examples/http/forward-proxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ var util = require('util'),
//
httpProxy.createServer({
forward: {
port: 9000,
port: 9019,
host: 'localhost'
}
}).listen(8000);
}).listen(8019);

//
// Target Http Forwarding Server
Expand All @@ -47,7 +47,7 @@ http.createServer(function (req, res) {
res.writeHead(200, { 'Content-Type': 'text/plain' });
res.write('request successfully forwarded to: ' + req.url + '\n' + JSON.stringify(req.headers, true, 2));
res.end();
}).listen(9000);
}).listen(9019);

util.puts('http proxy server '.blue + 'started '.green.bold + 'on port '.blue + '8000 '.yellow + 'with forward proxy'.magenta.underline);
util.puts('http forward server '.blue + 'started '.green.bold + 'on port '.blue + '9000 '.yellow);
util.puts('http proxy server '.blue + 'started '.green.bold + 'on port '.blue + '8019 '.yellow + 'with forward proxy'.magenta.underline);
util.puts('http forward server '.blue + 'started '.green.bold + 'on port '.blue + '9019 '.yellow);
10 changes: 5 additions & 5 deletions examples/http/latent-proxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ var proxy = httpProxy.createProxyServer();
http.createServer(function (req, res) {
setTimeout(function () {
proxy.web(req, res, {
target: 'http://localhost:9000'
target: 'http://localhost:9008'
});
}, 500);
}).listen(8000);
}).listen(8008);

//
// Target Http Server
Expand All @@ -48,7 +48,7 @@ http.createServer(function (req, res) {
res.writeHead(200, { 'Content-Type': 'text/plain' });
res.write('request successfully proxied to: ' + req.url + '\n' + JSON.stringify(req.headers, true, 2));
res.end();
}).listen(9000);
}).listen(9008);

util.puts('http proxy server '.blue + 'started '.green.bold + 'on port '.blue + '8000 '.yellow + 'with latency'.magenta.underline);
util.puts('http server '.blue + 'started '.green.bold + 'on port '.blue + '9000 '.yellow);
util.puts('http proxy server '.blue + 'started '.green.bold + 'on port '.blue + '8008 '.yellow + 'with latency'.magenta.underline);
util.puts('http server '.blue + 'started '.green.bold + 'on port '.blue + '9008 '.yellow);
4 changes: 2 additions & 2 deletions examples/http/proxy-http-to-https.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,6 @@ httpProxy.createProxyServer({
headers: {
host: 'google.com'
}
}).listen(8000);
}).listen(8011);

util.puts('http proxy server'.blue + ' started '.green.bold + 'on port '.blue + '8000'.yellow);
util.puts('http proxy server'.blue + ' started '.green.bold + 'on port '.blue + '8011'.yellow);
10 changes: 5 additions & 5 deletions examples/http/proxy-https-to-http.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,21 +40,21 @@ http.createServer(function (req, res) {
res.writeHead(200, { 'Content-Type': 'text/plain' });
res.write('hello http over https\n');
res.end();
}).listen(9000);
}).listen(9009);

//
// Create the HTTPS proxy server listening on port 8000
//
httpProxy.createServer({
target: {
host: 'localhost',
port: 9000
port: 9009
},
ssl: {
key: fs.readFileSync(path.join(fixturesDir, 'agent2-key.pem'), 'utf8'),
cert: fs.readFileSync(path.join(fixturesDir, 'agent2-cert.pem'), 'utf8')
}
}).listen(8000);
}).listen(8009);

util.puts('https proxy server'.blue + ' started '.green.bold + 'on port '.blue + '8000'.yellow);
util.puts('http server '.blue + 'started '.green.bold + 'on port '.blue + '9000 '.yellow);
util.puts('https proxy server'.blue + ' started '.green.bold + 'on port '.blue + '8009'.yellow);
util.puts('http server '.blue + 'started '.green.bold + 'on port '.blue + '9009 '.yellow);
10 changes: 5 additions & 5 deletions examples/http/proxy-https-to-https.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,16 @@ https.createServer(httpsOpts, function (req, res) {
res.writeHead(200, { 'Content-Type': 'text/plain' });
res.write('hello https\n');
res.end();
}).listen(9000);
}).listen(9010);

//
// Create the proxy server listening on port 443
//
httpProxy.createServer({
ssl: httpsOpts,
target: 'https://localhost:9000',
target: 'https://localhost:9010',
secure: false
}).listen(8000);
}).listen(8010);

util.puts('https proxy server'.blue + ' started '.green.bold + 'on port '.blue + '8000'.yellow);
util.puts('https server '.blue + 'started '.green.bold + 'on port '.blue + '9000 '.yellow);
util.puts('https proxy server'.blue + ' started '.green.bold + 'on port '.blue + '8010'.yellow);
util.puts('https server '.blue + 'started '.green.bold + 'on port '.blue + '9010 '.yellow);
10 changes: 5 additions & 5 deletions examples/http/standalone-proxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ var proxy = new httpProxy.createProxyServer();
http.createServer(function (req, res) {
setTimeout(function () {
proxy.web(req, res, {
target: 'http://localhost:9000'
target: 'http://localhost:9002'
});
}, 200);
}).listen(8000);
}).listen(8002);

//
// Target Http Server
Expand All @@ -48,7 +48,7 @@ http.createServer(function (req, res) {
res.writeHead(200, { 'Content-Type': 'text/plain' });
res.write('request successfully proxied to: ' + req.url + '\n' + JSON.stringify(req.headers, true, 2));
res.end();
}).listen(9000);
}).listen(9002);

util.puts('http server '.blue + 'started '.green.bold + 'on port '.blue + '8000 '.yellow + 'with proxy.web() handler'.cyan.underline + ' and latency'.magenta);
util.puts('http server '.blue + 'started '.green.bold + 'on port '.blue + '9000 '.yellow);
util.puts('http server '.blue + 'started '.green.bold + 'on port '.blue + '8002 '.yellow + 'with proxy.web() handler'.cyan.underline + ' and latency'.magenta);
util.puts('http server '.blue + 'started '.green.bold + 'on port '.blue + '9001 '.yellow);
10 changes: 5 additions & 5 deletions examples/middleware/gzip-middleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,13 @@ connect.createServer(
function (req, res) {
proxy.web(req, res);
}
).listen(8000);
).listen(8012);

//
// Basic Http Proxy Server
//
var proxy = httpProxy.createProxyServer({
target: 'http://localhost:9000'
target: 'http://localhost:9012'
});

//
Expand All @@ -59,7 +59,7 @@ http.createServer(function (req, res) {
res.writeHead(200, { 'Content-Type': 'text/plain' });
res.write('request successfully proxied to: ' + req.url + '\n' + JSON.stringify(req.headers, true, 2));
res.end();
}).listen(9000);
}).listen(9012);

util.puts('http proxy server'.blue + ' started '.green.bold + 'on port '.blue + '8000'.yellow);
util.puts('http server '.blue + 'started '.green.bold + 'on port '.blue + '9000 '.yellow);
util.puts('http proxy server'.blue + ' started '.green.bold + 'on port '.blue + '8012'.yellow);
util.puts('http server '.blue + 'started '.green.bold + 'on port '.blue + '9012 '.yellow);
10 changes: 5 additions & 5 deletions examples/middleware/modifyResponse-middleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,13 @@ connect.createServer(
function (req, res) {
proxy.web(req, res);
}
).listen(8000);
).listen(8013);

//
// Basic Http Proxy Server
//
var proxy = httpProxy.createProxyServer({
target: 'http://localhost:9000'
target: 'http://localhost:9013'
});

//
Expand All @@ -60,8 +60,8 @@ var proxy = httpProxy.createProxyServer({
http.createServer(function (req, res) {
res.writeHead(200, { 'Content-Type': 'text/plain' });
res.end('Hello, I know Ruby\n');
}).listen(9000);
}).listen(9013);

util.puts('http proxy server'.blue + ' started '.green.bold + 'on port '.blue + '8000'.yellow);
util.puts('http server '.blue + 'started '.green.bold + 'on port '.blue + '9000 '.yellow);
util.puts('http proxy server'.blue + ' started '.green.bold + 'on port '.blue + '8013'.yellow);
util.puts('http server '.blue + 'started '.green.bold + 'on port '.blue + '9013 '.yellow);

8 changes: 4 additions & 4 deletions examples/websocket/latent-websocket-proxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ catch (ex) {
// Create the target HTTP server and setup
// socket.io on it.
//
var server = io.listen(9000);
var server = io.listen(9016);
server.sockets.on('connection', function (client) {
util.debug('Got websocket connection');

Expand All @@ -60,7 +60,7 @@ server.sockets.on('connection', function (client) {
var proxy = new httpProxy.createProxyServer({
target: {
host: 'localhost',
port: 9000
port: 9016
}
});

Expand All @@ -78,12 +78,12 @@ proxyServer.on('upgrade', function (req, socket, head) {
}, 1000);
});

proxyServer.listen(8000);
proxyServer.listen(8016);

//
// Setup the socket.io client against our proxy
//
var ws = client.connect('ws://localhost:8000');
var ws = client.connect('ws://localhost:8016');

ws.on('message', function (msg) {
util.debug('Got message: ' + msg);
Expand Down
8 changes: 4 additions & 4 deletions examples/websocket/standalone-websocket-proxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ catch (ex) {
// Create the target HTTP server and setup
// socket.io on it.
//
var server = io.listen(9000);
var server = io.listen(9015);
server.sockets.on('connection', function (client) {
util.debug('Got websocket connection');

Expand All @@ -60,7 +60,7 @@ server.sockets.on('connection', function (client) {
var proxy = new httpProxy.createProxyServer({
target: {
host: 'localhost',
port: 9000
port: 9015
}
});
var proxyServer = http.createServer(function (req, res) {
Expand All @@ -75,12 +75,12 @@ proxyServer.on('upgrade', function (req, socket, head) {
proxy.ws(req, socket, head);
});

proxyServer.listen(8000);
proxyServer.listen(8015);

//
// Setup the socket.io client against our proxy
//
var ws = client.connect('ws://localhost:8000');
var ws = client.connect('ws://localhost:8015');

ws.on('message', function (msg) {
util.debug('Got message: ' + msg);
Expand Down
Loading

0 comments on commit bc236d7

Please sign in to comment.