Skip to content

refactor(api): extract cache-control header builder into a utility function #321

@JhaSourav07

Description

@JhaSourav07

🧩 Background

app/api/streak/route.ts and app/api/github/route.ts both compute Cache-Control header strings inline using similar ternary expressions.

🎯 Objective

Create utils/cacheControl.ts exporting buildCacheControlHeader({ refresh, random, secondsToMidnight }): string.

📁 Files to touch

  • utils/cacheControl.ts (new)
  • app/api/streak/route.ts
  • app/api/github/route.ts

🛠️ Implementation steps

  • Define the helper.
  • Add unit tests for all three branches (no-cache, no-store, s-maxage).
  • Use from both routes.

✅ Definition of done

  • Helper is tested.
  • Routes use the helper.
  • Existing route tests pass.

Metadata

Metadata

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions