Blame view

imports/client/app/utils/rate-limit.js 628 Bytes
c4d3e07d0   Deepak   added login/reset...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
  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);