Skip to content

Support serving Radar under a base path#1077

Open
nadaverell wants to merge 1 commit into
mainfrom
fix/base-path-serving
Open

Support serving Radar under a base path#1077
nadaverell wants to merge 1 commit into
mainfrom
fix/base-path-serving

Conversation

@nadaverell

@nadaverell nadaverell commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

Summary

Radar can now be hosted behind a no-strip-prefix ingress such as /radar. Operators can set a base path on the binary or Helm chart and the UI, API calls, MCP links, static assets, and worker scripts resolve under that prefix while root deployments continue to behave normally.

Closes #657.

What changed

  • Adds a --base-path flag for standalone/in-cluster serving and mounts the server routes under the normalized prefix.
  • Rewrites the served frontend index so subpath installs receive runtime apiBase, router basename, and asset base values before the app boots.
  • Reuses the existing RadarApp apiBase / basename plumbing instead of adding a persisted user setting or changing the library API.
  • Makes static asset helpers aware of the runtime asset base, including assets referenced from JavaScript chunks and the ELK layout worker.
  • Adds Helm basePath support, including liveness/readiness probe paths, plus short documentation for no-strip-prefix ingress setups.

Testing

  • go test ./internal/server ./internal/config ./internal/app
  • make tsc
  • make test
  • make build
  • jq empty deploy/helm/radar/values.schema.json
  • helm template radar deploy/helm/radar --set basePath=radar --show-only templates/deployment.yaml
  • Smoke-tested the built binary with --base-path /radar: prefixed health endpoint returned 200, unprefixed health returned 404, client routes served rewritten HTML, and JavaScript/worker assets served from the prefixed asset paths.
  • Smoke-tested root serving after the Vite asset-base change: deep links still resolve root asset URLs and /api/health remains unchanged.
  • Visual test skipped because this changes URL/static-serving behavior, not layout or rendered UI.

Note

Medium Risk
Changes HTTP routing and HTML rewriting for every request when a base path is set; misconfigured ingress or prefix mismatch could break UI/API, though empty base path preserves prior root behavior.

Overview
Adds subpath hosting for ingress setups that forward /radar/... to the app without stripping the prefix.

Operators can set --base-path (CLI) or Helm basePath. The server normalizes the prefix, mounts API and static routes under it, redirects / to the prefixed root, and returns 404 for unprefixed API paths when a base path is active. Liveness/readiness probe paths in the chart follow the same prefix.

For the SPA, served index.html is rewritten to inject window.__RADAR_RUNTIME_CONFIG__ (basePath, apiBase, assetBase) before module scripts load, and to prefix absolute/relative asset URLs. Standalone boot passes that into RadarApp via existing apiBase / basename plumbing. assetUrl (and ELK worker URL) honor the runtime asset base; several UI call sites switch hardcoded /api and image paths to apiUrl / routePath / assetUrl. Vite base: './' supports relative built assets at root while the server still normalizes ./assets to /assets when no prefix is set.

Docs and chart schema describe no-strip-prefix ingress; root deployments stay unchanged when basePath is empty.

Reviewed by Cursor Bugbot for commit 9172c83. Bugbot is set up for automated code reviews on this repo. Configure here.

@nadaverell nadaverell requested a review from hisco as a code owner July 1, 2026 12:44
Comment thread internal/server/server.go
if strings.Contains(p, "://") || strings.HasPrefix(p, "//") {
return "", fmt.Errorf("must be a path, not a URL")
}
if !strings.HasPrefix(p, "/") {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Ability to change the base path of the web services

2 participants