Skip to content

fix(domain): sync .env APP_URL when primary domain changes in the UI - #435

Merged
geodro merged 1 commit into
mainfrom
worktree-domain-update-env-sync
May 28, 2026
Merged

fix(domain): sync .env APP_URL when primary domain changes in the UI#435
geodro merged 1 commit into
mainfrom
worktree-domain-update-env-sync

Conversation

@geodro

@geodro geodro commented May 28, 2026

Copy link
Copy Markdown
Member

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.

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.
@geodro
geodro merged commit 87bf4f0 into main May 28, 2026
3 checks passed
@geodro
geodro deleted the worktree-domain-update-env-sync branch June 22, 2026 20:32
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.

1 participant