fix rate-limit.js module failing to block excessive requests

This commit is contained in:
cleverbeagle 2017-07-31 09:30:52 -05:00
parent 6bfe6a3947
commit 031f36759f
2 changed files with 5 additions and 11 deletions

View file

@ -1,18 +1,11 @@
import { Meteor } from 'meteor/meteor';
import { DDPRateLimiter } from 'meteor/ddp-rate-limiter';
import { _ } from 'meteor/underscore';
const fetchMethodNames = methods => _.pluck(methods, 'name');
const assignLimits = ({ methods, limit, timeRange }) => {
const methodNames = fetchMethodNames(methods);
export default ({ methods, limit, timeRange }) => {
if (Meteor.isServer) {
DDPRateLimiter.addRule({
name(name) { return _.contains(methodNames, name); },
name(name) { return methods.indexOf(name) > -1; },
connectionId() { return true; },
}, limit, timeRange);
}
};
export default function rateLimit(options) { return assignLimits(options); }