forked from soyjavi/zen-proxy-example
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
42 lines (37 loc) · 1.15 KB
/
test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
var http = require('http');
var hyperquest = require('hyperquest');
/* -- Random NODEJS servers (from :1981 to :1990) --------------------------- */
var delay, i, port, _i;
port = 1980;
delay = 10;
for (i = _i = 1; _i <= 10; i = ++_i) {
port++;
http.createServer(function(req, res) {
setTimeout(function() {
res.writeHead(200, {"Content-Type": "text/plain"});
res.write(JSON.stringify(req.headers, true, 2));
return res.end();
}, delay);
}).listen(port);
}
http.createServer(function(req, res) {
setTimeout(function() {
res.writeHead(302, {
'Location': 'http://tapquo.com'
});
res.end();
}, delay);
}).listen(2001);
/* -- Making calls ---------------------------------------------------------- */
var interval_id = setInterval(function(){proxy();}, 2500);
j = 0
var proxy = function() {
j = (j < 3) ? (j + 1) : 0
hyperquest('http://localhost:8888/random');
hyperquest('http://127.0.0.1:8888/roundrobin');
hyperquest('http://localhost:8888/regex/prefix-' + j + '/hello-' + j);
hyperquest('http://localhost:8888/unknown/url');
hyperquest('http://localhost:8888/redirect');
};
proxy();
process.stdout.setMaxListeners(0);