feat(api): cache GitHub star count server-side#24
Merged
Conversation
The header star badge fetched api.github.com directly from every visitor's browser, which is rate-limited to 60 req/hour per IP — heavy traffic from one IP made the count silently vanish. Add /api/github/stars, which fetches the count on the Worker and edge-caches it (cf cacheTtl 1h + Cache-Control), so GitHub is hit ~once/hour per colo regardless of traffic. Falls back to a sane default if upstream is unreachable. The badge now calls this same-origin endpoint instead of GitHub. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Rp5Ri2TcfaCozPfpkrTDkw
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
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.
Summary
GitHubStarBadgefetchedapi.github.comdirectly from every visitor's browser. GitHub's unauthenticated API is capped at 60 req/hour per IP, so heavy traffic from one IP exhausts it and the star count silently disappears (the component hides the count on a failed/403response)./api/github/stars— fetches the count on the Worker and edge-caches it (cf: { cacheTtl: 3600, cacheEverything }+Cache-Control), so GitHub is hit ~once/hour per colo regardless of visitor volume. Sends aUser-Agent(GitHub rejects API calls without one). Falls back to a sane default + shorter cache if upstream is unreachable.Test plan
src/routes/api/github/stars/server.test.ts— live count, network-failure fallback, and403/rate-limit fallback (3 tests, all pass)npm run check(0 errors) + lint clean on changed filespre-pushhook ran fullvalidate(lint + check + tests + build)/api/github/stars)🤖 Generated with Claude Code
https://claude.ai/code/session_01Rp5Ri2TcfaCozPfpkrTDkw