Blame view
imports/modules/rate-limit.js
559 Bytes
0b8062427
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
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); if (Meteor.isServer) { DDPRateLimiter.addRule({ name(name) { return _.contains(methodNames, name); }, connectionId() { return true; }, }, limit, timeRange); } }; export const rateLimit = (options) => assignLimits(options); |