Repository navigation
fix(webapps-neo): Serve the SPA from a configurable sub-path - #3678
Merged
Merged
Conversation
`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
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]>
|
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.



Closes #3677. Follow-up to #3514.
operaton.bpm.webapp.neo.application-pathis documented and has integration tests, but the SPA it configures only worked at the server root: with/app-neothe 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
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>inindex.htmlper request tocontextPath + applicationPath + "/". Registered on the existing resource chain besideSpaResourceResolver; onlyindex.htmlis 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.base: './'plus relative tags in the hand-writtenindex.html, with<base href="/">first in<head>.npm run devand a root deployment behave exactly as before; the literal/is what the transformer rewrites.app_root()/app_path()inconfig.jsread the declared root. Every<Route path>,href,route()target, the plugin manifest URL and i18next'sloadPathgo throughapp_path. Plugins keep declaring root-relative paths; the prefix is applied where they are rendered or routed to. At the rootapp_path("/tasks") === "/tasks", so a root deployment is byte-identical and no existing test needed adjusting.env.shdoes the same substitution fromDOCKER_RUN_PLACEHOLDER_APPLICATION_PATH;nginx.confserves 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 theDockerfile'sCOPY /app/dist— Vite writes totarget, so the image build was already broken.Environment Variables.md,Docker Build.md,.env.docker-run.Behaviour changes to be aware of
SpaResourceResolveralready 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 withindex-redirect-enabled).Tests
SpaIndexTransformerTest: root, sub-path, context path, single base tag, non-HTML and tag-less shells untouchedChangedAppPathIT: 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="/"app_pathat root / under a prefix / on a deep link,config.jsonfrom the app root, plugin manifest under a prefix (and a configuredpluginsUrlleft alone), i18nextloadPath, Header nav +aria-current+ logo under a prefixnpm run test:e2e:sub-path— builds the bundle, serves it behind/app-neoviae2e/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 withE2E_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/pathand the root (nginx -tplus curl of shell / assets / deep link / missing asset / redirects).Note for reviewers: the existing dev-server e2e suite fails on
mainin a fresh environment for unrelated reasons (login.spec.jsexpects a heading that no longer matches the translation, and the compose backend'sREST_AUTH_ENABLED=truemakesidentity/verifyreturn 401). Not touched here; worth its own issue.🤖 Generated with Claude Code
https://claude.ai/code/session_01Fr3Z98PQDXTJb4NU8FLvav