How to use rolling-rate-limiter - 1 common examples

To help you get started, we’ve selected a few rolling-rate-limiter examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github bwbwbwbw / DummyCTFPlatform / src / webControllers / public / challenge.js View on Github external
const eventBus = DI.get('eventBus');
  const userService = DI.get('userService');
  const contestService = DI.get('contestService');
  const submissionService = DI.get('submissionService');
  const systemPropertyService = DI.get('systemPropertyService');

  const logger = DI.get('logger');

  // cache scoreboard
  let scoreboardCache = null;
  eventBus.on('contest.challenge.visibilityChanged', () => scoreboardCache = null);
  eventBus.on('contest.current.changed', () => scoreboardCache = null);
  eventBus.on('contest.submission.passed', () => scoreboardCache = null);
  eventBus.on('contest.registrant.new', () => scoreboardCache = null);

  const registrantLimiter = promisify(RateLimiter({
    redis: DI.get('redis'),
    namespace: 'limiter-flag-user',
    interval: 5 * 60 * 1000,
    maxInInterval: 10,
  }));

  async function enforceCurrentContestExists(req, res, next) {
    const contestId = await systemPropertyService.get('current_contest', '');
    if (!contestId) {
      next(new UserError(i18n.__('error.contest.notfound')));
      return;
    }
    req.contestId = contestId;
    next();
  }

rolling-rate-limiter

Rate limiter that supports a rolling window, either in-memory or backed by Redis

MIT
Latest version published 2 years ago

Package Health Score

53 / 100
Full package analysis

Popular rolling-rate-limiter functions