Skip to content

Add public cache key, logging, token cache TTL#107

Merged
admdly merged 2 commits intomainfrom
refactor/security
May 5, 2026
Merged

Add public cache key, logging, token cache TTL#107
admdly merged 2 commits intomainfrom
refactor/security

Conversation

@admdly
Copy link
Copy Markdown
Contributor

@admdly admdly commented May 5, 2026

No description provided.

Copilot AI review requested due to automatic review settings May 5, 2026 03:44
@cloudflare-workers-and-pages
Copy link
Copy Markdown

cloudflare-workers-and-pages Bot commented May 5, 2026

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
api 9506a0e Commit Preview URL

Branch Preview URL
May 05 2026, 03:48 AM

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR improves cache behavior and error handling across the API worker by (1) normalizing public cache keys to avoid cache fragmentation from query strings, (2) adding/adjusting logging and sanitizing user-facing 500 errors, and (3) introducing a TTL-based in-memory cache for the /versions/v1/update bearer token to reduce repeated KV reads.

Changes:

  • Add publicCacheKey / normalizePublicCacheKey and apply it to Hono cache middleware for public versions and stats routes.
  • Add centralized logging for unhandled errors and avoid exposing internal exception messages in API responses (app + central-alerts).
  • Add a 60s TTL to the in-memory UPDATE_TOKEN cache and expand tests around token rotation and error sanitization.

Reviewed changes

Copilot reviewed 14 out of 14 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
src/lib/cache.ts Adds helpers to normalize public cache keys (drops query/hash) and a Hono keyGenerator.
src/services/versions/v1/index.ts Adds token-cache TTL for update auth and uses publicCacheKey for cached public routes.
src/services/stats/v1/index.ts Uses publicCacheKey for cached stats routes to avoid query-string cache fragmentation.
src/services/central-alerts/v1/index.ts Logs database errors while returning a generic error message to clients.
src/app/index.ts Logs unhandled errors and returns a consistent generic “Internal Server Error” response.
test/lib/cache.test.ts Adds unit coverage for cache-key normalization behavior.
test/services/versions/v1/index.test.ts Adds a token-rotation/TTL test and resets the in-memory token cache between tests.
test/services/versions/v1/errors.test.ts Verifies generic 500 responses don’t expose internal details and resets token cache between tests.
test/services/versions/v1/middleware.test.ts Resets token cache between tests to avoid cross-test contamination.
test/services/central-alerts/v1/index.test.ts Adds coverage ensuring DB exception details are not exposed in responses.
test/integration/versions/index.test.ts Resets token cache between integration tests.
test/integration/app.test.ts Resets token cache between full-app integration tests.
test/app/index.test.ts Resets token cache between app-level tests.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/services/versions/v1/index.ts
@admdly admdly merged commit b82e5ed into main May 5, 2026
8 checks passed
@admdly admdly deleted the refactor/security branch May 5, 2026 03:50
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.

2 participants