fix(webui): use relative asset base so fonts and lazy chunks honor X-Forwarded-Prefix (#10889)#10904
Open
localai-org-maint-bot wants to merge 1 commit into
Open
fix(webui): use relative asset base so fonts and lazy chunks honor X-Forwarded-Prefix (#10889)#10904localai-org-maint-bot wants to merge 1 commit into
localai-org-maint-bot wants to merge 1 commit into
Conversation
…Forwarded-Prefix (#10889) The Vite build emitted path-absolute asset URLs (base: '/'). index.html entry scripts and the favicon were rewritten to include the reverse-proxy prefix in serveIndex, but two reference kinds are not in index.html and so bypassed that rewrite: - CSS `url()` font references (e.g. Font Awesome .woff2), which the browser resolves relative to the stylesheet and which `<base href>` never affects - lazily-imported route chunks, whose preload base came from the absolute Vite base Under a subpath mount (X-Forwarded-Prefix: /llm/) both were fetched from the origin root, 404ing — missing-glyph "tofu" icons and broken lazy-loaded pages. Switch Vite to a relative base ('./') so every generated URL resolves against the file that references it: CSS fonts and route chunks now load from `/llm/assets/...`, and index.html's now-relative entry refs resolve via the `<base href>` serveIndex already injects on every response. Root deployments are unaffected. The existing path-absolute rewrite in app.go still covers the public `/favicon.svg`. Signed-off-by: Ettore Di Giacinto <mudler@localai.io> Assisted-by: Claude:opus-4.8 [Claude Code]
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.
What
Fixes #10889.
When LocalAI is served under a reverse-proxy subpath (
X-Forwarded-Prefix: /llm/), Web UI fonts render as missing-glyph "tofu" and some lazy-loaded route chunks 404, because they are fetched from the origin root instead of under the prefix.Root cause
The Vite build used
base: '/', emitting path-absolute asset URLs.serveIndex(core/http/app.go) rewrites the entry<script>/<link>and favicon inindex.htmlto include the prefix, and injects a<base href>. But two reference kinds live outsideindex.htmland bypass that rewrite:url()font references (Font Awesome.woff2) — the browser resolves these relative to the stylesheet, and<base href>never affects CSSurl().base.Both resolved to
/assets/...(origin root), skipping the/llm/prefix → 404.Fix
Switch Vite to a relative base (
base: './'). Every generated URL now resolves against the file that references it:/llm/assets/*.woff2✅/llm/assets/*.js✅index.html's now-relative entry refs resolve via the<base href>serveIndexalready injects on every response (middleware.BaseURLis never empty), so this works for both proxied and root deployments.The public
/favicon.svg(referenced absolutely in the sourceindex.html) is still covered by the existing path-absolute rewrite inapp.go.Verification
npm run buildoutput confirms the emitted paths are now relative:index.html:src="./assets/index-*.js",href="./assets/index-*.css"url(./fa-solid-900-*.woff2)(was/assets/...)"/assets/"absolute references remain in the built JSThe existing reverse-proxy assertions in
core/http/app_test.go(<base href>injection; body must not contain="/assets/or="/favicon.svg"under a prefix) continue to hold.Assisted-by: Claude:opus-4.8 [Claude Code]