fix(server): strip baseHRef prefix from asset paths in static file server#16151
Open
irwinrex wants to merge 2 commits into
Open
fix(server): strip baseHRef prefix from asset paths in static file server#16151irwinrex wants to merge 2 commits into
irwinrex wants to merge 2 commits into
Conversation
…rver When baseHRef is set to a non-root value (e.g. /argo-workflows/), the browser requests assets relative to that path (e.g. /argo-workflows/main.js). The static file server was using the full request path directly to look up files in the embedded filesystem, causing a mismatch since the embedded assets are at the root level. This resulted in index.html being served instead of the actual JS/CSS files, causing syntax errors. Now the baseHRef prefix is stripped from the request path before checking asset existence and serving files, while still preserving the SPA fallback behavior for client-side routes.
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.
When baseHRef is set to a non-root value (e.g. /argo-workflows/), the browser requests assets relative to that path (e.g. /argo-workflows/main.js). The static file server was using the full request path directly to look up files in the embedded filesystem, causing a mismatch since the embedded assets are at the root level. This resulted in index.html being served instead of the actual JS/CSS files, causing syntax errors. Now the baseHRef prefix is stripped from the request path before checking asset existence and serving files, while still preserving the SPA fallback behavior for client-side routes.
Fixes #TODO
Motivation
When Argo Workflows is deployed behind an AWS ALB (Application Load Balancer) on EKS, the ALB forwards requests at a subpath (e.g.,
/argo-workflows/*) to the Argo Server without stripping the path prefix. The--base-hrefflag is used to inform the browser that all assets are relative to/argo-workflows/. However, the static file server did not account for this prefix when resolving asset requests internally, causing all JS/CSS files to be served asindex.htmlinstead. This broke the UI entirely withUncaught SyntaxError: expected expression, got '<'.This is a common deployment pattern — ALB ingress rules typically map a path prefix to a service without path rewriting (unlike nginx ingress which supports
rewrite-target). The fix ensures the server correctly handles requests with the baseHRef prefix regardless of whether the reverse proxy strips it.Modifications
server/static/static.go: ModifiedServerFiles()to strip thebaseHRefprefix fromr.URL.Pathbefore checking whether a UI asset exists and before serving it viahttp.FileServer. The normalization handles both/argo-workflows/and/argo-workflowsformats.Verification
server/static/static_test.gopass/main.jswith root baseHRef → returns JS (regression)/argo-workflows/main.jswith/argo-workflows/baseHRef → returns JS (fix)/argo-workflows/→ returns index.html with correct<base href>/argo-workflows/workflows/foo(SPA route) → returns index.html (fallback preserved)Documentation
No documentation changes needed — this is a bug fix that makes the existing
--base-href/ARGO_BASE_HREFfeature work correctly.AI
None
For the ALB part specifically: AWS Load Balancer Controller on EKS uses pathType: Prefix with ALB. Unlike nginx ingress (which supports nginx.ingress.kubernetes.io/rewrite-target: /$2 to strip path prefixes), ALB forwards the full request path to the target service.I know we can use ALB Urlwrite to use prefix path still the issue exits.This means the Argo Server must handle requests like /argo-workflows/main.js directly, which is exactly what this fix enables.
Signed-off-by: Irwin Rex irwinrex.a@gmail.com