fix examples handling of response headers#3825
Open
KyleAMathews wants to merge 3 commits intomainfrom
Open
Conversation
✅ Deploy Preview for electric-next ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #3825 +/- ##
=======================================
Coverage 87.68% 87.68%
=======================================
Files 23 23
Lines 2078 2078
Branches 547 549 +2
=======================================
Hits 1822 1822
Misses 254 254
Partials 2 2
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Fix tanstack and yjs proxy examples that were stripping or selectively copying Electric response headers instead of forwarding them all through. - tanstack: stop stripping Electric's CORS headers, just forward everything - yjs: return Electric's response directly instead of manually copying headers (which had a hardcoded outdated list); remove exposeHeaders from Hono CORS config so it doesn't overwrite Electric's Access-Control-Expose-Headers - Improve MissingHeadersError to say "forward all response headers" - Update troubleshooting docs with clearer guidance https://claude.ai/code/session_01AojeAHp8bJWABAEYRM8cup
7348c79 to
2f10453
Compare
commit: |
…omments - Always construct a new Response with mutable headers in yjs proxy so Hono's CORS middleware can merge its headers in (Node.js fetch returns immutable headers which caused CORS headers to be silently dropped) - Update stale comments to match simplified proxy behavior - Combine and clarify MissingHeadersError message - Improve troubleshooting docs with CORS explanation Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
@balegas - Is this related to my error? If so, will I need to update anything on how the electric_query_params? |
Contributor
No, just consolidating examples. |
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
Simplify proxy examples to forward all response headers from Electric instead of selectively managing individual headers. This fixes
MissingHeadersErrorthat users hit when proxies strip Electric's CORS headers.Root Cause
Users running Electric behind a proxy were getting
MissingHeadersErrorbecause the example proxy code was selectively copying headers — either missing newly added Electric headers or stripping CORS headers likeaccess-control-expose-headers. The yjs example had an additional subtle bug: it manually copied headers into a newResponsewhile also hardcoding a list ofelectric-*headers, creating a maintenance burden every time Electric added a new header.Approach
Instead of maintaining an explicit list of headers to forward, the proxies now pass through all response headers from Electric, only removing
content-encodingandcontent-length(which become invalid whenfetch()decompresses the body).Key changes:
access-control-expose-headersnew Response()using a mutable copy of the upstream headers. Always constructs a newResponse(not just in thecontent-encodingbranch) because Node.jsfetch()returns immutable headers that Hono's CORS middleware can't merge intoMissingHeadersErrorto give actionable guidance about forwarding all headers, specifically mentioningaccess-control-expose-headersKey Invariants
Responsewith mutable headers so framework middleware (e.g., Hono CORS) can add its own headerscontent-encodingandcontent-lengthshould be stripped, and only when the proxy decompresses the bodyaccess-control-expose-headersheader must reach the browser for the client to readelectric-*headersNon-goals
CORS_HEADERSconstant, which is still used for non-proxy responses (health, POST/DELETE, errors)Verification
Review the example proxy code to confirm all Electric headers pass through:
Files changed
examples/tanstack/src/server/app.jsexamples/yjs/src/server/server.tsexposeHeadersCORS config and manual header copying, always create mutable Responsepackages/typescript-client/src/error.tsMissingHeadersErrorwith actionable proxy guidancewebsite/docs/guides/troubleshooting.md🤖 Generated with Claude Code