mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-17 06:37:23 +01:00
25 lines
614 B
JavaScript
25 lines
614 B
JavaScript
var nconf = require('nconf');
|
|
var limiter = require('connect-ratelimit');
|
|
|
|
var IS_PROD = nconf.get('NODE_ENV') === 'production';
|
|
|
|
module.exports = function(app) {
|
|
// TODO review later
|
|
// disable the rate limiter middleware
|
|
if (/*!IS_PROD || */true) return;
|
|
app.use(limiter({
|
|
end:false,
|
|
categories:{
|
|
normal: {
|
|
// 2 req/s, but split as minutes
|
|
totalRequests: 80,
|
|
every: 60000
|
|
}
|
|
}
|
|
})).use(function(req,res,next){
|
|
//logging.info(res.ratelimit);
|
|
if (res.ratelimit.exceeded) return res.json(429,{err:'Rate limit exceeded'});
|
|
next();
|
|
});
|
|
};
|