MCPcopy Create free account
hub / github.com/CopilotKit/OpenGenerativeUI / isRateLimited

Function isRateLimited

apps/app/src/app/api/copilotkit/route.ts:17–24  ·  view source on GitHub ↗
(ip: string)

Source from the content-addressed store, hash-verified

15const hits = new Map<string, number[]>();
16
17function isRateLimited(ip: string): boolean {
18 if (!RATE_LIMIT_ENABLED) return false;
19 const now = Date.now();
20 const timestamps = hits.get(ip)?.filter(t => t > now - RATE_LIMIT_WINDOW_MS) ?? [];
21 timestamps.push(now);
22 hits.set(ip, timestamps);
23 return timestamps.length > RATE_LIMIT_MAX;
24}
25
26// Prune stale entries every 5 min to prevent unbounded memory growth
27if (RATE_LIMIT_ENABLED) {

Callers 1

POSTFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected