SPB Git forge

spb/spb-cloud

Public
10commits 1branches 0releases
3.2 MBsize
maindefault branch
1 h agolast push
JavaScript 56.7% TypeScript 42.6%
609 B · 30 lines typescript
Raw Blame History
1import { RateLimiterMemory } from "rate-limiter-flexible";23const loginLimiter = new RateLimiterMemory({4  points: 5,5  duration: 60, // 5 attempts per minute6});78const apiLimiter = new RateLimiterMemory({9  points: 100,10  duration: 60, // 100 requests per minute11});1213export async function checkLoginRateLimit(ip: string): Promise<boolean> {14  try {15    await loginLimiter.consume(ip);16    return true;17  } catch {18    return false;19  }20}2122export async function checkApiRateLimit(ip: string): Promise<boolean> {23  try {24    await apiLimiter.consume(ip);25    return true;26  } catch {27    return false;28  }29}30