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

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