Add base-path so the web UI can be served under a path prefix#17
Merged
Conversation
3 tasks
florianl
reviewed
May 5, 2026
florianl
left a comment
Owner
There was a problem hiding this comment.
Thanks for the contribution!
Just a minor issue: Can we use strings.ReplaceAll() instead of the boiler platte, that is introduced by html/template?
Contributor
Author
|
Thank you @florianl! |
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.
Summary
--base-pathflag andBASE_PATHenv var to allow serving the web UI and API under a sub-path prefix (e.g./firepit)fetch()calls use the correct prefixed URLs/to<base-path>/when a base path is configuredMotivation
On the OTel Demo Firepit will be deployed behind Envoy.
Without this change the browser fetches
/api/*instead of/<whatever>/api/*, breaking the UI entirely.Changes
cmd/firepit/main.goBasePath stringtoConfigand wired up the flag/env varnormalizeBasePathenforces a leading slash and strips any trailing slashstartWebUIServerrefactored intobuildWebUIMux(testable without starting a real listener) andstartWebUIServer/,/api/*,/debug/pprof/*) are now prefixed withcfg.BasePathindex.htmlis served as a parsed Go template that injects{{.BasePath}}into awindow.__BASE_PATH__script tag; all other static assets are served by the existing stripped file serverBasePath != "", a redirect handler sends/→<base-path>/cmd/firepit/web/index.html<script>window.__BASE_PATH__ = '{{.BasePath}}';</script>in<head>fetch()calls now prefix withwindow.__BASE_PATH__cmd/firepit/main_test.goTestNormalizeBasePath— unit tests for the normalization helperTestLoadConfigBasePath— env var parsing, including edge cases (/, trailing slash, no leading slash)TestWebUIServerBasePath— integration-style tests usingbuildWebUIMuxdirectly, covering redirect behaviour and prefixed routes for both the empty and/firepitcases