forked from pkedy/throttle-concurrent-users
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathproxy.js
38 lines (30 loc) · 879 Bytes
/
proxy.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
var connect = require('connect');
var http = require('http');
var throttle = require('./lib/throttle.js');
var cookieParser = require('cookie-parser');
var redis = require('redis');
var baseUrl = 'http://localhost:80';
var cleanup = process.argv.indexOf('--cleanup') != -1;
var options = {
maxAllowed: 2,
activeTimeout: 60 * 1,
waitingTimeout: 60 * 5
}
function initializeHttp() {
var app = connect();
app.use(cookieParser());
app.use(throttle.preFilter());
app.use(throttle.proxy(baseUrl));
http.createServer(app).listen(9000);
}
var client = redis.createClient(6379, 'localhost');
client.on('connect', function() {
console.log('Connected to Redis... Starting http server.');
throttle.setClient(client);
throttle.setOptions(options);
initializeHttp();
if (cleanup) {
console.log('Starting background cleanup process.');
throttle.startCleanup();
}
});