feat(dashboard): support serving under URL prefix via X-Forwarded-Prefix#19450
Closed
cmcgrabby-hue wants to merge 1 commit into
Closed
feat(dashboard): support serving under URL prefix via X-Forwarded-Prefix#19450cmcgrabby-hue wants to merge 1 commit into
cmcgrabby-hue wants to merge 1 commit into
Conversation
The Hermes dashboard previously assumed it was served at the root of its host (e.g. https://kanban.tilos.com/). When mounted behind a path-prefix reverse proxy (e.g. https://mission-control.tilos.com/hermes/), the SPA 404'd because: - index.html shipped absolute /assets/index-*.js URLs - React Router had no basename - The plugin loader hit /dashboard-plugins/<name>/... at the root host - CSS in the bundle had absolute url(/fonts/...) references This patch makes the dashboard prefix-aware at runtime, no rebuild required. The proxy injects 'X-Forwarded-Prefix: /hermes' on every request and the Python server: - Rewrites href/src in served index.html to '${prefix}/assets/...' - Injects 'window.__HERMES_BASE_PATH__="${prefix}"' for the SPA to read - Rewrites url() refs in CSS at serve time The SPA reads window.__HERMES_BASE_PATH__ once at boot and: - Prefixes all /api/... fetches via api.ts - Prefixes all /dashboard-plugins/... script/css URLs in usePlugins - Sets <BrowserRouter basename={...}> so client-side routing works When no X-Forwarded-Prefix header is present, behavior is unchanged (empty prefix => serves at root, kanban.tilos.com keeps working). Refs: MC-AUTO-13
19 tasks
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
Make the Hermes dashboard work when served under a non-root URL prefix
(e.g.
https://mission-control.tilos.com/hermes/) instead of only atthe host root (e.g.
https://kanban.tilos.com/).Why
The Mission Control dashboard at mission-control.tilos.com wants to
surface the Hermes Kanban dashboard as a tab in its own nav, served
inside the same domain so SSO + cookie scope is unified. CF Tunnel
routes
mission-control.tilos.com/hermes/*through a small local Caddythat strips the
/hermes/prefix and forwards to the dashboard withX-Forwarded-Prefix: /hermes. Before this PR the dashboard 404'd becausethe built SPA shipped absolute asset URLs and React Router had no basename.
How
Runtime, not rebuild — same
web_distworks at root AND under any prefix.Server (
hermes_cli/web_server.py):_normalise_prefix()parses + validatesX-Forwarded-Prefix(rejects
.., control chars, oversize values)._serve_index(prefix)rewrites<head>asset paths and injectswindow.__HERMES_BASE_PATH__for the SPA to read.serve_cssroute intercepts CSS asset requests BEFORE theStaticFiles mount and rewrites
url(/fonts/...)references when aprefix is in play.
Frontend (
web/src/):lib/api.tsexportsHERMES_BASE_PATH(read from window) and prefixesit onto every
/api/...fetch.plugins/usePlugins.tsprefixes/dashboard-plugins/...script + cssURLs.
main.tsxpassesbasename={HERMES_BASE_PATH || undefined}to<BrowserRouter>.When
X-Forwarded-Prefixis absent (the kanban.tilos.com path), theprefix is empty and behavior is identical to before.
Verified locally
Single dashboard process at
127.0.0.1:9119, then:curl http://127.0.0.1:9119/kanban→ root mode, asset paths absolute/assets/...→ still works on kanban.tilos.com.curl -H 'X-Forwarded-Prefix: /hermes' http://127.0.0.1:9119/kanban→ asset paths rewritten to
/hermes/assets/...,window.__HERMES_BASE_PATH__="/hermes"set,CSS
url(/fonts/...)rewritten tourl(/hermes/fonts/...).https://mission-control.tilos.com/hermes/kanban→Pages Function → CF Tunnel → local Caddy (strips /hermes) → :9119
with header → renders correctly.
Out of scope
respective repos and are not touched here.
kanban.tilos.comkeeps working unchanged as a fallback URL.Refs: MC-AUTO-13