1
0
mirror of https://github.com/Foltik/Shimapan synced 2024-12-12 06:20:46 -05:00
shimapan/app/util/rateLimit.js

13 lines
453 B
JavaScript
Raw Normal View History

2019-01-02 15:20:53 -05:00
const config = require('config');
const rateLimit = require('express-rate-limit');
2019-01-02 16:47:18 -05:00
const defaultSkipFn = (req, res) =>
res.statusCode !== 401 && res.statusCode !== 403 && res.statusCode !== 422;
const rateLimitRequest = (window, max, skipFn) =>
2019-01-02 15:20:53 -05:00
config.get('RateLimit.enable')
2019-01-02 16:47:18 -05:00
? rateLimit({windowMs: window * 1000, max: max, skip: skipFn || defaultSkipFn})
2019-01-02 15:20:53 -05:00
: (req, res, next) => { next(); };
module.exports = rateLimitRequest;