mirror of
https://github.com/Foltik/Shimapan
synced 2024-11-14 16:59:57 -05:00
13 lines
453 B
JavaScript
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;
|