Skip to content

Support serving the GUI behind a reverse-proxy sub-path - #4

Open
Slav4ik wants to merge 1 commit into
testsmith-io:mainfrom
Slav4ik:feat/base-path-awareness
Open

Support serving the GUI behind a reverse-proxy sub-path#4
Slav4ik wants to merge 1 commit into
testsmith-io:mainfrom
Slav4ik:feat/base-path-awareness

Conversation

@Slav4ik

@Slav4ik Slav4ik commented Jul 22, 2026

Copy link
Copy Markdown

Fixes #3

Summary

Makes the WireMock GUI work when served behind a path-based reverse proxy (e.g. https://host/wiremock/__admin/gui) without requiring a custom rebuild or fork.

Changes

1. Relative asset paths + runtime <base href> (vite.config.ts, index.html)

  • Switched Vite base from the hardcoded absolute /__admin/gui/ to './', so the build emits relative asset references (./assets/...).
  • Added a small inline script in index.html that runs before the module script and injects a <base href> derived from window.location.pathname up to and including /__admin/gui/.

This ensures relative asset URLs resolve against the actual page location, not the host root.

2. API base URL prefix preservation (App.tsx)

  • Updated getDefaultBaseUrl() to return origin + <prefix> where <prefix> is the pathname segment before /__admin.
  • Example: page at /wiremock/__admin/gui → API base https://host/wiremock (requests go to https://host/wiremock/__admin/...).

Existing localStorage override and http://localhost:8080 dev fallback are unchanged.

Backward compatibility

Root-mounted deployments (https://host/__admin/gui) are unaffected:

Scenario <base href> Asset ./assets/x.js resolves to API base
Root mount /__admin/gui /__admin/gui/ /__admin/gui/assets/x.js https://host
Prefixed mount /wiremock/__admin/gui /wiremock/__admin/gui/ /wiremock/__admin/gui/assets/x.js https://host/wiremock

In the prefixed case, the browser sends requests with the /wiremock prefix; the reverse proxy strips it before forwarding to WireMock, which still sees /__admin/gui/assets/... and /__admin/....

Build verification

npm ci && npm run build   # webapp/

Emitted dist/index.html (excerpt):

<script>/* runtime <base href> injection */</script>
<script type="module" crossorigin src="./assets/index-Fp2cjh1i.js"></script>
<link rel="stylesheet" crossorigin href="./assets/index-CjuQgt2G.css">

Asset paths are relative (./assets/...), not absolute (/__admin/gui/assets/...). Combined with the runtime <base href>, they resolve correctly for both root and prefixed mounts as shown in the table above.

Test plan

  • Load GUI at http://localhost:8080/__admin/gui — assets load, API calls succeed
  • Load GUI at http://localhost:8080/wiremock/__admin/gui via a reverse proxy that strips /wiremock — assets load, API calls succeed
  • Vite dev server (npm run dev) still works for local development

Made with Cursor

Use relative Vite asset paths with a runtime <base href> derived from
the page URL, and preserve any path prefix before /__admin in the API
base URL so the GUI works at both /__admin/gui and /<prefix>/__admin/gui.

Co-authored-by: Cursor <cursoragent@cursor.com>
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.

Support serving the GUI behind a reverse-proxy sub-path (base-path awareness)

1 participant