mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-17 14:47:53 +01:00
refactor middlewares in their own folder, move buildFiles to libs/buildFiles
This commit is contained in:
21
website/src/middlewares/apiThrottle.js
Normal file
21
website/src/middlewares/apiThrottle.js
Normal file
@@ -0,0 +1,21 @@
|
||||
var nconf = require('nconf');
|
||||
|
||||
var IS_PROD = nconf.get('NODE_ENV') === 'production';
|
||||
|
||||
module.exports = function(app) {
|
||||
if (!IS_PROD) return;
|
||||
app.use(limiter({
|
||||
end:false,
|
||||
catagories:{
|
||||
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();
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user