forked from dharmafly/connect-ratelimit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
example.js
27 lines (25 loc) · 810 Bytes
/
example.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
var connect = require('connect'),
http = require('http'),
limiter = require('./index');
var app = connect()
.use(limiter({
// end: true,
blacklist: ['127.0.0.1'],
categories: {
blacklist: {
totalRequests: 3,
// totalRequests: 0,
// totalRequests: -1,
//every: 10000
}
}
}))
.use(function (req, res) {
if (res.ratelimit.exceeded) {
res.end(res.ratelimit.client.name + ' exceeded the rate limit!');
}
res.end('Hello world!');
});
http.createServer(app).listen(4000, function () {
console.log('Example server on ' + 4000);
});