Skip to content

fix(shared): default DA admin to stage on localhost#1104

Open
benpeter wants to merge 2 commits into
mainfrom
locstage
Open

fix(shared): default DA admin to stage on localhost#1104
benpeter wants to merge 2 commits into
mainfrom
locstage

Conversation

@benpeter

Copy link
Copy Markdown

Problem

Opening a site in the local dev server (e.g. http://localhost:3020/#/benpeter/hlx6-test) redirects to /not-found, even though the same site loads fine on prod da.live.

Root cause is an environment mismatch between da-live and da-nx for the localhost host:

  • On localhost, the IMS token is always minted against IMS stage (da-nx's env resolver maps localhost -> dev, and dev -> the stg1 IMS environment). This is not overridable per request.
  • da-live's own env resolver (blocks/shared/constants.js getDaEnv) had no concept of localhost and defaulted every backend to prod. So DA_ORIGIN pointed at admin.da.live (prod).
  • A stage IMS token sent to prod admin gets a 401. da-live's daFetch (blocks/shared/utils.js) redirects to /not-found on a 401 against a DA origin after one refresh attempt — hence the redirect.

da-nx (nx2) already defaults its DA_ADMIN to stage on localhost, so the two halves of the app disagreed about which admin to talk to.

Fix

Align da-live's admin default with da-nx: on localhost, DA_ORIGIN / getDaAdmin() now default to stage-admin.da.live, matching the stage IMS token. A stage token now reaches stage admin, which returns 403/404 (not 401) for a not-yet-authorized config read — and da-live's daFetch returns on 403 rather than redirecting, so the browser falls through to the default editor instead of /not-found.

Scope is deliberately narrow — admin only. Content, collab, and preview origins keep their existing prod default (with the existing ?da-content=stage / ?da-collab=stage manual overrides unchanged). Explicit overrides (?da-admin=prod, ?da-admin=reset) still win everywhere.

getDaEnv gains an optional localDefault parameter (defaults to prod, so all other callers are unchanged) and now keys off url.hostname.includes("local"), matching da-nx's own localhost detection.

Verification

  • Unit suite green (1603 passed, 4 skipped); lint clean.
  • New tests in test/unit/blocks/shared/constants.test.js assert localhost -> stage-admin, non-local -> prod, and explicit-override precedence.
  • Live-tested against the running dev server: the served constants.js resolves DA_ORIGIN = https://stage-admin.da.live on localhost, https://admin.da.live with ?da-admin=prod, and https://admin.da.live on prod da.live; content/collab origins unchanged in all cases.

Follow-up

da-live maintaining its own env resolver in parallel with da-nx's is the underlying source of this drift. A follow-up could consolidate da-live onto nx2's DA_ADMIN / env resolution so the two can never disagree again.

benpeter added 2 commits July 14, 2026 19:05
On localhost the IMS token is always minted against IMS stage (da-nx env
resolves localhost to 'dev' -> stage). da-live's own env resolver defaults
localhost to prod, so a stage token hits prod admin.da.live -> 401 ->
/not-found. Add a failing test asserting localhost defaults to stage-admin.
On localhost the IMS token is always minted against IMS stage (da-nx
resolves a localhost host to env 'dev', which targets stage for both the
token and nx2's DA_ADMIN). da-live's own env resolver defaulted localhost
to prod, so the stage token hit prod admin.da.live, got a 401, and da-nx's
daFetch redirected the browser to /not-found.

Align da-live with da-nx by defaulting the da-admin backend to stage on
localhost (content/collab/preview keep their existing prod default and the
documented ?da-collab=stage override). An explicit ?da-admin= param still
wins, and non-local hosts are unaffected.

Update tests that derived URLs from the localhost DA_ORIGIN to build the
expected value from DA_ORIGIN instead of hardcoding the prod host.
@aem-code-sync

aem-code-sync Bot commented Jul 14, 2026

Copy link
Copy Markdown

Hello, I'm the AEM Code Sync Bot and I will run some actions to deploy your branch.
In case there are problems, just click the checkbox below to rerun the respective action.

  • Re-sync branch
Commits

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