Skip to content

Instantly share code, notes, and snippets.

View slavaGanzin's full-sized avatar

Slava slavaGanzin

View GitHub Profile
@slavaGanzin
slavaGanzin / ratelimiter.js
Created February 5, 2024 10:39
basic rate limiter
const requestLimit = new Map();
const requestLimitWindow = [];
const CLEANUP_INTERVAL = 100;
const TEST_RATE = 5;
const IP_LIMIT = 10;
const getLimitKey = () => {
const now = new Date();
return `${now.getHours()}:${now.getMinutes()}:${now.getSeconds().toString().padStart(2, '0')}`;