Skip to content

refactor(cors): expose Link/X-Request-Id/Idempotency-Replay/RateLimit-* globally#94

Merged
CryptoJones merged 1 commit into
masterfrom
refactor/cors-expose-headers
May 18, 2026
Merged

refactor(cors): expose Link/X-Request-Id/Idempotency-Replay/RateLimit-* globally#94
CryptoJones merged 1 commit into
masterfrom
refactor/cors-expose-headers

Conversation

@CryptoJones
Copy link
Copy Markdown
Owner

Summary

  • server.js cors() gains an exposedHeaders list covering Link, X-Request-Id, Idempotency-Replay, and the three RateLimit-* headers from express-rate-limit. One global declaration; covers error paths too.
  • 15 list endpoints previously hand-rolled Access-Control-Expose-Headers: Link — now removed (redundant).

Test plan

  • tests/api/cors-expose-headers.test.js (2 cases): asserts the exposed-headers set + pins the "no controller hand-rolls it" cleanup.
  • Full suite: 474 pass / 4 skip (was 472/4).
  • Lint clean.

This code proudly made in Nebraska. GO BIG RED! 🌽 https://xkcd.com/2347/

…-* globally

Browser JS clients hitting the API cross-origin couldn't read most
of the useful response headers — CORS hides everything outside the
safelist unless `Access-Control-Expose-Headers` covers it
explicitly.

Two changes:

1. **server.js**: cors() middleware gains an `exposedHeaders` list
   covering Link, X-Request-Id, Idempotency-Replay, and the three
   RateLimit-* headers that express-rate-limit emits. One declaration
   instead of N per-controller setHeader calls; covers every route
   uniformly including error paths.

2. **app/controllers/*.js**: 15 list endpoints previously did
   `res.setHeader('Access-Control-Expose-Headers', 'Link')` after
   setting the Link header itself. With the global CORS declaration
   in place those are redundant — removed across the board.

Tests:
- New `tests/api/cors-expose-headers.test.js` (2 cases) pins
  the exposed header set on a cross-origin response AND asserts
  no controller hand-rolls the expose header (regression guard
  against the redundant pattern coming back).
- Full suite: 474 pass / 4 skip (was 472/4).
- Lint clean.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@CryptoJones CryptoJones merged commit 41548a6 into master May 18, 2026
3 checks passed
@CryptoJones CryptoJones deleted the refactor/cors-expose-headers branch May 18, 2026 05:43
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