feat(registry): edge cache /api/registry/** via Nitro routeRules#36
Merged
Conversation
Set 5 min browser / 1 h edge fresh + 24 h SWR on the registry lookup route so Cloudflare Pages bypasses the Worker on repeat CLI lookups. Route rules are extracted to app/route-rules.ts so a bun test can assert them without pulling in Nuxt's auto-import graph. Refs #34
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
6 tasks
Contributor
There was a problem hiding this comment.
No issues found across 8 files
Auto-approved: Isolated configuration change adding edge caching headers via Nitro routeRules with corresponding unit tests; very low risk of breakage and high performance benefit.
Architecture diagram
sequenceDiagram
participant CLI as CLI / Browser
participant CF as Cloudflare Edge (Cache API)
participant Worker as Pages Worker (Nitro)
participant Content as Nuxt Content (@nuxt/content)
Note over CLI,Content: Registry API Request Flow (/api/registry/**)
CLI->>CF: GET /api/registry/vercel/next.js
alt NEW: Cache HIT (Within 1h s-maxage)
CF-->>CLI: 200 OK (Served from Edge)
Note right of CF: cf-cache-status: HIT<br/>Worker bypassed (Cost saved)
else Cache MISS or STALE
CF->>Worker: Forward Request
Worker->>Worker: CHANGED: Apply routeRules
Worker->>Content: Query registry markdown
Content-->>Worker: Registry Data
Worker->>Worker: NEW: Inject REGISTRY_CACHE_CONTROL
Note right of Worker: public, max-age=300, s-maxage=3600, swr=86400
Worker-->>CF: 200 OK + Cache Headers
CF->>CF: Store in Edge Cache
CF-->>CLI: 200 OK
Note right of CF: cf-cache-status: MISS/DYNAMIC
end
opt NEW: Stale-While-Revalidate (Between 1h and 24h old)
Note over CF,Worker: Background Revalidation
CF-->>CLI: 200 OK (Stale Data)
CF->>Worker: Async Fetch (Refresh Cache)
Worker->>Content: Query latest markdown
Content-->>Worker: Data
Worker-->>CF: Updated Data
CF->>CF: Update Cache (Fresh for next 1h)
end
This was referenced Apr 8, 2026
Merged
Merged
Merged
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
Cache
/api/registry/**responses at the Cloudflare edge via NitrorouteRules. On a cache HIT the Pages Worker is bypassed entirely via the Cache API, cutting Worker CPU/request cost and improving CLI latency for repeatask docs addlookups.Route rules are extracted to
apps/registry/app/route-rules.tsso the assertion test can import the constants directly without pulling in Nuxt's auto-import graph.Closes #34
Changes
apps/registry/app/route-rules.ts— new, exportsREGISTRY_CACHE_CONTROL+registryApiRouteRulesapps/registry/nuxt.config.ts— wirerouteRules: registryApiRouteRulesapps/registry/test/nuxt-config.test.ts— new, static config assertion (bun test)apps/registry/package.json— addtestscript.please/docs/tracks/active/registry-edge-cache-20260408/— track artifactsVerification Checklist
cache-controlheader matchespublic, max-age=300, s-maxage=3600, stale-while-revalidate=86400(bun run --cwd apps/registry test)bun run --cwd packages/cli test→ 227 pass / 0 failcurl -sI https://<pages-url>/api/registry/vercel/next.jstwice → second call showscf-cache-status: HITmax-age + swrwindow without manual purgeOut of Scope
If-None-Match(follow-up track)Test Plan
bun run --cwd apps/registry testpassesbun run --cwd packages/cli testpassescf-cache-status: HITon deployed PagesSummary by cubic
Edge-cache
/api/registry/**at Cloudflare using NitrorouteRulesso cache hits bypass the Pages Worker, reducing cost and speeding up repeated CLI registry lookups. Implements #34 with 5 min browser TTL and 1 h edge fresh + 24 h SWR.apps/registry/app/route-rules.tsexportingREGISTRY_CACHE_CONTROLandregistryApiRouteRuleswithcache-control: public, max-age=300, s-maxage=3600, stale-while-revalidate=86400.routeRulesinapps/registry/nuxt.config.tsto enable edge caching for/api/registry/**.apps/registry/test/nuxt-config.test.tsto assert the header and cache settings; addedtestscript inapps/registry/package.json..please/docs/tracks/completed/registry-edge-cache-20260408/and updated.please/docs/tracks.jsonl.Written for commit 3938282. Summary will update on new commits.