add simple rate limiter
This commit is contained in:
parent
b7f25852d5
commit
52671cf093
10
insight.js
10
insight.js
@ -111,9 +111,6 @@ if (!config.disableHistoricSync) {
|
|||||||
if (peerSync) peerSync.allowReorgs = true;
|
if (peerSync) peerSync.allowReorgs = true;
|
||||||
|
|
||||||
|
|
||||||
// express settings
|
|
||||||
require('./config/express')(expressApp, historicSync, peerSync);
|
|
||||||
|
|
||||||
// routes
|
// routes
|
||||||
require('./config/routes')(expressApp);
|
require('./config/routes')(expressApp);
|
||||||
|
|
||||||
@ -131,9 +128,14 @@ if (config.enableRatelimiter) {
|
|||||||
require('./plugins/ratelimiter').init(expressApp, config.ratelimiter);
|
require('./plugins/ratelimiter').init(expressApp, config.ratelimiter);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// express settings
|
||||||
|
require('./config/express')(expressApp, historicSync, peerSync);
|
||||||
|
|
||||||
|
|
||||||
//Start the app by listening on <port>
|
//Start the app by listening on <port>
|
||||||
server.listen(config.port, function() {
|
server.listen(config.port, function() {
|
||||||
console.log('insight server listening on port %d in %s mode', server.address().port, process.env.NODE_ENV);
|
logger.info('insight server listening on port %d in %s mode', server.address().port, process.env.NODE_ENV);
|
||||||
});
|
});
|
||||||
|
|
||||||
//expose app
|
//expose app
|
||||||
|
|||||||
@ -7,4 +7,28 @@ module.exports.init = function(app, config) {
|
|||||||
preconditions.checkArgument(app);
|
preconditions.checkArgument(app);
|
||||||
logger.info('Using ratelimiter plugin');
|
logger.info('Using ratelimiter plugin');
|
||||||
|
|
||||||
|
config = config || {};
|
||||||
|
config.whitelistRPH = config.whitelistRPH || 5000;
|
||||||
|
config.normalRPH = config.normalRPH || 1;
|
||||||
|
|
||||||
|
console.log('asdasdasd');
|
||||||
|
app.use(limiter({
|
||||||
|
whitelist: [],
|
||||||
|
blacklist: ['localhost'], // 'example.com'
|
||||||
|
categories: {
|
||||||
|
whitelist: {
|
||||||
|
totalRequests: config.whitelistRPH,
|
||||||
|
every: 60 * 60 * 1000
|
||||||
|
},
|
||||||
|
blacklist: {
|
||||||
|
totalRequests: 0,
|
||||||
|
every: 0
|
||||||
|
},
|
||||||
|
normal: {
|
||||||
|
totalRequests: config.normalRPH,
|
||||||
|
every: 60 * 60 * 1000
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user