Skip to content

Custom Sync Server URL#12459

Merged
tiensonqin merged 3 commits intologseq:masterfrom
hoellen:feat/dbsync-custom
Apr 13, 2026
Merged

Custom Sync Server URL#12459
tiensonqin merged 3 commits intologseq:masterfrom
hoellen:feat/dbsync-custom

Conversation

@hoellen
Copy link
Copy Markdown
Contributor

@hoellen hoellen commented Mar 18, 2026

This PR adds a setting to configure a custom sync server URL for self-hosted sync. The URL is persisted in localStorage and used to derive both the WebSocket and HTTP base URLs at runtime, replacing the previous compile-time constants.

What changed

  • Settings UI: New "Sync server URL" entry in the advanced settings section (desktop + mobile). Opens a dialog to enter, save, or reset the URL. Changes are pushed to the db worker immediately so they take effect without restarting.
image
  • handler/user.cljs: rtc-group? returns true when a custom sync server is configured, bypassing group membership checks. Self-hosted servers don't enforce group membership, so this is intentional.

Tests

  • Unit tests for new functions in config_test.cljs.

@CLAassistant
Copy link
Copy Markdown

CLAassistant commented Mar 18, 2026

CLA assistant check
All committers have signed the CLA.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds support for configuring a custom DB-sync server base URL (persisted in localStorage) to enable self-hosted sync servers, and adjusts runtime URL derivation for both HTTP and WebSocket sync endpoints. It also updates snapshot streaming to avoid double-gzip decompression issues when fetch() auto-decompresses but leaves the content-encoding: gzip header intact.

Changes:

  • Add a new “Sync server URL” advanced setting (desktop + mobile) and a dialog to save/reset the custom URL; immediately pushes updated sync config to the DB worker.
  • Replace compile-time DB-sync URL constants with runtime functions that derive WS/HTTP URLs from the optional custom base.
  • Simplify response-body-stream to always use resp.body and update tests to match real-world fetch() decompression behavior.

Reviewed changes

Copilot reviewed 12 out of 12 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
src/main/frontend/config.cljs Adds custom sync server URL persistence + URL derivation helpers and runtime getters for WS/HTTP bases.
src/main/frontend/components/settings.cljs Adds desktop settings row + dialog UI; pushes updated sync config to worker.
src/main/mobile/components/settings.cljs Adds mobile settings entry that opens the same dialog and shows current/default URL.
src/main/frontend/handler/events/ui.cljs Adds event handler to open the sync server settings dialog.
src/main/frontend/handler/user.cljs Updates rtc-group? gating to allow RTC when a custom sync server is configured.
src/main/frontend/persist_db/browser.cljs Updates worker init to call runtime URL getters.
src/main/frontend/components/repo.cljs Updates worker sync-config setup to call runtime URL getters.
src/main/frontend/handler/db_based/sync.cljs Uses runtime sync base getters; simplifies response body streaming to avoid double-decompression.
src/main/frontend/spec/storage.cljc Adds local-storage spec entry for the sync server URL key.
src/resources/dicts/en.edn Adds i18n strings for the new sync server URL settings UI.
src/test/frontend/config_test.cljs Adds unit tests for URL normalization/derivation helpers and defaults.
src/test/frontend/handler/db_based/sync_test.cljs Updates snapshot streaming test to reflect real-world fetch() auto-decompression behavior.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/main/frontend/components/settings.cljs Outdated
Comment on lines +81 to +84
"Return true when `url` looks like a valid HTTP(S) base URL."
[url]
(and (string? url)
(re-find #"^https?://" url)))
Copy link

Copilot AI Mar 30, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

valid-sync-server-url? is currently a simple regex prefix check, which will accept strings like "https://" (no host) and other malformed URLs that will later fail at fetch/WebSocket time. Consider validating via js/URL parsing (and ensuring protocol is http/https and hostname is present) so the UI can reliably reject invalid inputs.

Suggested change
"Return true when `url` looks like a valid HTTP(S) base URL."
[url]
(and (string? url)
(re-find #"^https?://" url)))
"Return true when `url` is a syntactically valid HTTP(S) base URL
with a non-empty hostname."
[url]
(when (string? url)
(try
(let [u (js/URL. url)
protocol (.-protocol u)
hostname (.-hostname u)]
(and (#{"http:" "https:"} protocol)
(seq hostname)))
(catch :default _
false))))

Copilot uses AI. Check for mistakes.
Comment thread src/resources/dicts/en.edn Outdated
@hoellen hoellen force-pushed the feat/dbsync-custom branch from 9a3b4d8 to f338fed Compare April 9, 2026 11:36
@hoellen
Copy link
Copy Markdown
Contributor Author

hoellen commented Apr 9, 2026

@tiensonqin I rebased my branch on current master. I removed the commit 9a3b4d8 as you fixed it on master.
Let me know if I need to change something or if I should include any of the suggestions from the Copilot review.

@tiensonqin
Copy link
Copy Markdown
Contributor

@hoellen Sorry for the late reply, I still have some work to finish on sync, mostly to ensure client/server checksum matches. I'll check this PR asap.

Copy link
Copy Markdown
Contributor

@tiensonqin tiensonqin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

QAed on web/mobile/desktop apps, works great! 🚢 👍

hoellen and others added 3 commits April 13, 2026 12:59
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@tiensonqin tiensonqin merged commit 8997638 into logseq:master Apr 13, 2026
2 checks passed
tiensonqin added a commit that referenced this pull request Apr 14, 2026
* Add custom sync server

Co-authored-by: Tienson Qin <tiensonqin@gmail.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@hoellen hoellen deleted the feat/dbsync-custom branch April 16, 2026 07:22
deephbz added a commit to deephbz/logseq-fork that referenced this pull request Apr 18, 2026
Mirror the Custom Sync Server URL pattern (logseq#12459) for the single-page
publish service. Settings -> Advanced -> Publish server URL opens a
dialog that writes the URL to localStorage; frontend.config/publish-api-base
reads it on each call so URL changes take effect without a restart.

Unlike sync, publish does not need a push-config-to-worker step because
the handler is purely HTTP request-response with no long-lived connection.
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.

4 participants