ix(db-sync): support comma-separated DB_SYNC_BASE_URL for multi-origin access - #12908
Open
SSamDav wants to merge 6 commits into
Open
ix(db-sync): support comma-separated DB_SYNC_BASE_URL for multi-origin access#12908SSamDav wants to merge 6 commits into
SSamDav wants to merge 6 commits into
Conversation
…in access
Allow DB_SYNC_BASE_URL to be a comma-separated list of URLs so the
self-hosted sync server accepts requests arriving via different addresses
(e.g. LAN IP over HTTP and a Tailscale/nginx domain over HTTPS) without
running separate server instances.
- config.cljs: parse DB_SYNC_BASE_URL into :base-urls vector; keep
:base-url as the first entry for backwards compatibility
- server.cljs: request-origin-opts returns a vector of {:scheme :host}
maps; add parse-url-origin helper
- platform/node.cljs: request-from-node accepts the origins vector and
matches the incoming Host header to pick the right scheme+host, falling
back to the first configured origin
- test: update node-server-request-origin test to reflect new behaviour
Fixes: logseq/db-test#1011
fix(db-sync): support comma-separated DB_SYNC_BASE_URL for multi-origin access
Contributor
|
@SSamDav Please sign CLA first. |
Author
|
Signed the CLA |
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.
Problem
When running a self-hosted db-sync server accessible via multiple addresses (e.g.
http://192.168.1.x:8787on LAN andhttps://logseq.tailscale-domainvia a Tailscale/nginx proxy), only one address could be configured inDB_SYNC_BASE_URL. Clients connecting via a different address would have their request URLs reconstructed with the wrong host, breaking sync.Fixes: logseq/db-test#1011
Solution
Allow
DB_SYNC_BASE_URLto accept a comma-separated list of URLs:The server now matches the incoming request's
Hostheader against all configured origins and picks the rightscheme://hostpair for URL reconstruction. Falls back to the first configured origin if no match is found.Changes
config.cljs: parseDB_SYNC_BASE_URLinto:base-urlsvector; keep:base-urlas the first entry for backwards compatibilityserver.cljs:request-origin-optsreturns a vector of{:scheme :host}maps; addparse-url-originhelperplatform/node.cljs:request-from-nodeaccepts the origins vector and matches the incomingHostheader to pick the right scheme+hostnode_server_test.cljs: update test to reflect new behaviourBackwards compatibility
Single-URL config (
DB_SYNC_BASE_URL=http://....) continues to work unchanged.