Skip to content

feat(api): cache GitHub star count server-side#24

Merged
fullstackjam merged 1 commit into
mainfrom
feat/cached-github-stars
Jun 26, 2026
Merged

feat(api): cache GitHub star count server-side#24
fullstackjam merged 1 commit into
mainfrom
feat/cached-github-stars

Conversation

@fullstackjam

Copy link
Copy Markdown
Member

Summary

  • The header GitHubStarBadge fetched api.github.com directly 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/403 response).
  • Add /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 a User-Agent (GitHub rejects API calls without one). Falls back to a sane default + shorter cache if upstream is unreachable.
  • The badge now calls this same-origin endpoint instead of GitHub directly — no per-visitor rate-limit exposure.

Test plan

  • src/routes/api/github/stars/server.test.ts — live count, network-failure fallback, and 403/rate-limit fallback (3 tests, all pass)
  • npm run check (0 errors) + lint clean on changed files
  • pre-push hook ran full validate (lint + check + tests + build)
  • After deploy: confirm the header badge shows the star count again (served from /api/github/stars)

🤖 Generated with Claude Code

https://claude.ai/code/session_01Rp5Ri2TcfaCozPfpkrTDkw

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

codecov Bot commented Jun 26, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@fullstackjam fullstackjam merged commit 5503bb2 into main Jun 26, 2026
8 checks passed
@fullstackjam fullstackjam deleted the feat/cached-github-stars branch June 26, 2026 06:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant