| | @@ -11,7 +11,10 @@ const WINDOW_MS = 60_000; |
| | const MAX_REQ = 120; // per IP per window, across /api/* |
| | |
| | type Bucket = { count: number; resetAt: number }; |
| - | const buckets = new Map<string, Bucket>(); |
| + | // Anchor on globalThis so the counter survives middleware module re-evaluation |
| + | // within the same Node process (plain module-level state can be reset). |
| + | const g = globalThis as unknown as { __docketBuckets?: Map<string, Bucket> }; |
| + | const buckets: Map<string, Bucket> = (g.__docketBuckets ??= new Map()); |
| | |
| | function clientIp(req: NextRequest): string { |
| | const xff = req.headers.get("x-forwarded-for"); |