feat: per-user token-bucket rate limit on /api/logs (FWC26) - #1123
Merged
greatest0fallt1me merged 2 commits intoJul 29, 2026
Merged
Conversation
- Add GET /api/logs and POST /api/logs endpoints (src/routes/logs.ts)
- Both routes require auth (requireAuth) and are guarded by a per-user
token-bucket rate limiter (createTokenBucketRateLimitMiddleware)
- Bucket config driven by new env vars with safe defaults:
LOGS_RATE_LIMIT_CAPACITY=60 (burst ceiling per user)
LOGS_RATE_LIMIT_REFILL_RATE=1 (tokens refilled per second)
- On bucket exhaustion: HTTP 429 + Retry-After header +
{ code, message, requestId, retryAfterMs } body
- Key resolution: JWT userId → x-user-id header → client IP
- Register /api/logs in src/routes/index.ts
- 30+ focused tests in src/routes/logs.test.ts covering:
happy paths, auth, validation, rate-limit 429, per-user isolation,
Retry-After semantics, shared-limiter across GET+POST, factory opts
- Documented in README.md (Logs Endpoint section + env vars table)
- Documented in .env.example (LOGS_RATE_LIMIT_* entries)
Closes #FWC26
|
@mrteeednut007-dotcom Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
Contributor
|
All good — merging. 🚀 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
feat: per-user token-bucket rate limit on /api/logs (FWC26)
Summary
Implements the GET /api/logs and POST /api/logs endpoints with a per-user token-bucket rate
limiter as required by the GrantFox FWC26 campaign spec.
What changed
New: src/routes/logs.ts
the canonical success envelope { data: { logs: [...] }, meta: { total } }
201 with the created entry
requestId, retryAfterMs }
Config: src/config/env.ts + src/config/index.ts
Route registration: src/routes/index.ts
Tests: src/routes/logs.test.ts (30+ cases)
Docs: README.md + .env.example
Testing
npm test -- --testPathPattern logs
Checklist
Closes #890