rate-limit.js
628 Bytes
import { _ } from 'meteor/underscore';
import { Meteor } from 'meteor/meteor';
import { DDPRateLimiter } from 'meteor/ddp-rate-limiter';
const fetchMethodNames = (methods) => _.pluck(methods, 'name');
const assignLimits = ({ methods, limit, timeRange }) => {
const methodNames = fetchMethodNames(methods);
if (Meteor.isServer) {
DDPRateLimiter.addRule({
name(name) { return _.contains(methodNames, name); },
connectionId() { return true; },
}, limit, timeRange);
}
};
export const rateLimit = (options) => assignLimits(options);