fix(domain): sync .env APP_URL when primary domain changes in the UI - #435
Merged
Conversation
The web UI's domain mutation handlers regenerated the vhost, reissued the cert, wrote container hosts, and reloaded nginx, but never touched the project's .env. So renaming the primary domain from the domain modal left APP_URL pointing at the old host, with VITE_REVERB_HOST and the other reverb keys stale alongside it. The CLI's runDomainAdd and runDomainRemove had the right guard already, but the UI is the only surface that can rename a domain in place (the CLI has no domain edit subcommand), which is why the gap was only visible through the web UI. Extract siteops.SyncEnvIfPrimaryChanged as the single seam both surfaces call when the primary domain changes. The helper runs envfile.SyncPrimaryDomain on the parent site (only the keys already present in the .env), then iterates gitpkg.DetectWorktrees and rewrites each worktree's APP_URL to <branch>.<newPrimary> via envfile.UpdateAppURL, matching what migrate_tld does on a full-site rename. The three UI handlers (domain:add, domain:edit, domain:remove) and the two CLI handlers (runDomainAdd, runDomainRemove) all route through it, collapsing five copies of the same conditional. The UI now logs a stderr warning on sync failure so the lerd-ui journal has a trace, matching the CLI's existing [WARN] line.
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.
The web UI's domain mutation handlers regenerated the vhost, reissued the cert, and reloaded nginx, but never touched the project's .env. So renaming the primary domain from the domain modal left APP_URL pointing at the old host with VITE_REVERB_HOST and the other reverb keys stale alongside it. The CLI's runDomainAdd and runDomainRemove already had the right guard, but the UI is the only surface that can rename a domain in place since the CLI has no domain edit subcommand, which is why the gap was only visible through the web UI.
Extract siteops.SyncEnvIfPrimaryChanged as the seam both surfaces call when the primary changes. The helper runs envfile.SyncPrimaryDomain on the parent site (touching only the keys already present in the .env, so it never adds anything you didn't already have) and then iterates gitpkg.DetectWorktrees to rewrite each worktree's APP_URL to . via envfile.UpdateAppURL, matching what migrate_tld does on a full-site rename. The three UI handlers and the two CLI handlers all route through it, collapsing five copies of the same conditional. UI handlers now log a stderr warning on sync failure so the lerd-ui journal has a trace, matching the CLI's existing [WARN] style. Worktree .env files now follow the parent rename, which neither surface did before for the regular add/remove flow.