Fix data feed failing on Cloudflare preview - #182
Merged
Conversation
Resolves data feed failures when visiting PR preview URLs for the first time. The issue occurred because Cloudflare's edge cache was serving CORS responses without considering the requesting origin. Root Cause: Cloudflare's cache uses only the URL as the cache key by default. When different origins (pr-123, pr-184, etc.) request the same URL, they would receive the same cached response, including CORS headers meant for a different origin. This caused CORS errors when the browser rejected the mismatched Access-Control-Allow-Origin header. The Fix: Add Vary: Origin header to all CORS responses. This tells Cloudflare (and other caches) to include the Origin request header in the cache key, ensuring each origin gets its own cached response with correct CORS headers. Additional improvements: - Reduce CORS preflight cache to 10 seconds for staging/preview environments (down from 5 minutes) to allow quick recovery from any deployment issues - Production keeps 5 minute preflight cache for optimal performance This is the standard solution for caching origin-specific CORS responses.
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.
Resolves data feed failures when visiting PR preview URLs for the first time. The issue occurred because Cloudflare's edge cache was serving CORS responses without considering the requesting origin.
Root Cause:
Cloudflare's cache uses only the URL as the cache key by default. When different origins (pr-123, pr-184, etc.) request the same URL, they would receive the same cached response, including CORS headers meant for a different origin. This caused CORS errors when the browser rejected the mismatched Access-Control-Allow-Origin header.
The Fix:
Add Vary: Origin header to all CORS responses. This tells Cloudflare (and other caches) to include the Origin request header in the cache key, ensuring each origin gets its own cached response with correct CORS headers.
Additional improvements:
This is the standard solution for caching origin-specific CORS responses.