import { Meteor } from 'meteor/meteor'; import { DDPRateLimiter } from 'meteor/ddp-rate-limiter'; export default ({ methods, limit, timeRange }) => { if (Meteor.isServer) { DDPRateLimiter.addRule({ name(name) { return methods.indexOf(name) > -1; }, connectionId() { return true; }, }, limit, timeRange); } }; // Same idea for subscriptions. DDPRateLimiter matches subscribe calls only when // the rule pins `type: 'subscription'`, so this is a separate helper. export const rateLimitSubscriptions = ({ subscriptions, limit, timeRange }) => { if (Meteor.isServer) { DDPRateLimiter.addRule({ type: 'subscription', name(name) { return subscriptions.indexOf(name) > -1; }, connectionId() { return true; }, }, limit, timeRange); } };