Skip to content

fix(webapps-neo): Serve the SPA from a configurable sub-path - #3678

Merged
lambdaschmied2 merged 2 commits into
mainfrom
fix/webapps-neo-spa-sub-path
Oct 21, 2026
Merged

lambdaschmied2 merged 2 commits into
mainfrom
fix/webapps-neo-spa-sub-path

Conversation

@lambdaschmied2

Copy link
Copy Markdown
Contributor

Closes #3677. Follow-up to #3514.

operaton.bpm.webapp.neo.application-path is documented and has integration tests, but the SPA it configures only worked at the server root: with /app-neo the shell loaded, then its assets 404ed, then the locales, then the router matched nothing. Every defect is the bundle assuming its root is /.

The one model everything follows

https://host /operaton /app-neo /tasks/start
             └─ context ┴─ app-path ─┘ └─ route (client only)

Nothing in the bundle can know its prefix at build time, so the server states it in <base href> and everything hangs off that.

Changes

  • SpaIndexTransformer (Spring Boot starter) rewrites <base href> in index.html per request to contextPath + applicationPath + "/". Registered on the existing resource chain beside SpaResourceResolver; only index.html is transformed, and the existing tag is replaced rather than a second one inserted (two base tags and the first wins, silently). The href is fixed for the life of the deployment, so the chain cache is safe — asserted in a test rather than assumed.
  • Relative asset URLs. Vite base: './' plus relative tags in the hand-written index.html, with <base href="/"> first in <head>. npm run dev and a root deployment behave exactly as before; the literal / is what the transformer rewrites.
  • app_root() / app_path() in config.js read the declared root. Every <Route path>, href, route() target, the plugin manifest URL and i18next's loadPath go through app_path. Plugins keep declaring root-relative paths; the prefix is applied where they are rendered or routed to. At the root app_path("/tasks") === "/tasks", so a root deployment is byte-identical and no existing test needed adjusting.
  • Standalone image. env.sh does the same substitution from DOCKER_RUN_PLACEHOLDER_APPLICATION_PATH; nginx.conf serves the bundle from the prefix by stripping it rather than moving files, redirects / and the bare prefix to <prefix>/, and emits relative redirects. Also fixes the Dockerfile's COPY /app/dist — Vite writes to target, so the image build was already broken.
  • Docs: Environment Variables.md, Docker Build.md, .env.docker-run.

Behaviour changes to be aware of

  • In the nginx image a request for a missing asset (last segment with an extension) now 404s instead of being answered with the HTML shell. This matches what SpaResourceResolver already does on the Spring side; a broken deployment is now visible rather than hidden behind a blank page.
  • / in the nginx image redirects to the application path when one is configured (as the Spring starter already does with index-redirect-enabled).

Tests

Level What
Java unit SpaIndexTransformerTest: root, sub-path, context path, single base tag, non-HTML and tag-less shells untouched
Java IT ChangedAppPathIT: base href, same href on the cached second request, deep link → shell, the script the shell references is served under the prefix and is not root-absolute; EmptyAppPathIT: href="/"
vitest app_path at root / under a prefix / on a deep link, config.json from the app root, plugin manifest under a prefix (and a configured pluginsUrl left alone), i18next loadPath, Header nav + aria-current + logo under a prefix
Playwright npm run test:e2e:sub-path — builds the bundle, serves it behind /app-neo via e2e/sub-path-server.mjs (base-href rewrite + SPA fallback + 404 for missing assets), logs in, clicks to a second page, hard-reloads on the deep route, asserts no failed same-origin requests. Also passes with E2E_APP_PATH="". Opt-in because it needs a production build and a backend.

Verified additionally against a real nginx container at /app-neo, /my/application/path and the root (nginx -t plus curl of shell / assets / deep link / missing asset / redirects).

Note for reviewers: the existing dev-server e2e suite fails on main in a fresh environment for unrelated reasons (login.spec.js expects a heading that no longer matches the translation, and the compose backend's REST_AUTH_ENABLED=true makes identity/verify return 401). Not touched here; worth its own issue.

🤖 Generated with Claude Code

https://claude.ai/code/session_01Fr3Z98PQDXTJb4NU8FLvav

`operaton.bpm.webapp.neo.application-path` moved the filter chain, the API
namespace and the root redirect, but the bundle only worked at the server
root: assets and locales were fetched root-absolutely and every
`<Route path>` started at `/`, so `/app-neo/` reached the shell and stopped.

Nothing in the bundle can know its own prefix at build time (context path
plus application path, both per request), so the server states it in
`<base href>` and everything hangs off that:

- adds `SpaIndexTransformer`, which rewrites the base href of `index.html`
  on the way out; registered on the resource chain beside
  `SpaResourceResolver`
- builds with Vite `base: './'` and relative tags in `index.html`, so assets
  resolve against the base from any deep route
- adds `app_root()` / `app_path()` to config.js; prefixes every route, link
  and `route()` target, the plugin manifest and i18next's `loadPath` through
  them. Plugins keep declaring root-relative paths
- does the same substitution in the standalone image (`env.sh`); nginx
  serves the bundle from the prefix without moving files, and a missing
  asset now 404s there instead of being answered with the shell, matching
  `SpaResourceResolver`
- fixes the image's `COPY` source (Vite writes to `target`, not `dist`)
- at the server root `app_path` prefixes nothing, so a root deployment is
  unchanged and no existing test needed adjusting
- tests: `SpaIndexTransformerTest`; `ChangedAppPathIT` asserts the base
  href (also on the cached second request), a deep link and an asset under
  the prefix; `EmptyAppPathIT` the root; vitest for `app_path`, the
  manifest, the locales path and the prefixed navigation; a Playwright
  suite driving the built bundle behind a prefix (`npm run
  test:e2e:sub-path`), the only level that catches the routing half

related to #3677, #3514

Assisted-by: Claude:claude-opus-5
Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Fr3Z98PQDXTJb4NU8FLvav
@lambdaschmied2 lambdaschmied2 added bug Something isn't working scope:webapp-neo Changes affecting the new webapps. labels Sep 14, 2026
@github-actions github-actions Bot added documentation Improvements or additions to documentation lang:java Pull requests that update Java code lang:javascript Pull requests that update Javascript code scope:spring-boot Changes to the Spring Boot starter. scope:tests Changes affecting only test code labels Sep 14, 2026
Conflicts were all in webapps-neo/frontend, where main reformatted the
files and added features (authorized-app guards, branding, collapsible
dashboard sections, task list queries). Resolved by taking main's
version and re-applying app_path() to every route, link and route()
target, including the ones main added (super-process link, auto-select
of the first task, task list return with list query).

- vite.config.js: main's function form with devBaseHref, plus base: "./"
- Header: nav entries filtered by authorized apps first, then prefixed
- branding.js: the default logo goes through app_path, as the hard-coded
  logo did before
- Header.test.jsx: kept both main's authorization tests and the
  sub-path navigation test

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@sonarqubecloud

Copy link
Copy Markdown

@lambdaschmied2
lambdaschmied2 merged commit 394691a into main Oct 21, 2026
14 checks passed
@kthoms kthoms added this to the 2.2.0 milestone Oct 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working documentation Improvements or additions to documentation lang:java Pull requests that update Java code lang:javascript Pull requests that update Javascript code scope:spring-boot Changes to the Spring Boot starter. scope:tests Changes affecting only test code scope:webapp-neo Changes affecting the new webapps.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

webapps-neo does not work when served from a sub-path (application-path)

2 participants