Support serving the GUI behind a reverse-proxy sub-path - #4
Open
Slav4ik wants to merge 1 commit into
Open
Conversation
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>
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.
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)basefrom the hardcoded absolute/__admin/gui/to'./', so the build emits relative asset references (./assets/...).index.htmlthat runs before the module script and injects a<base href>derived fromwindow.location.pathnameup 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)getDefaultBaseUrl()to returnorigin + <prefix>where<prefix>is the pathname segment before/__admin./wiremock/__admin/gui→ API basehttps://host/wiremock(requests go tohttps://host/wiremock/__admin/...).Existing
localStorageoverride andhttp://localhost:8080dev fallback are unchanged.Backward compatibility
Root-mounted deployments (
https://host/__admin/gui) are unaffected:<base href>./assets/x.jsresolves to/__admin/gui/__admin/gui//__admin/gui/assets/x.jshttps://host/wiremock/__admin/gui/wiremock/__admin/gui//wiremock/__admin/gui/assets/x.jshttps://host/wiremockIn the prefixed case, the browser sends requests with the
/wiremockprefix; the reverse proxy strips it before forwarding to WireMock, which still sees/__admin/gui/assets/...and/__admin/....Build verification
Emitted
dist/index.html(excerpt):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
http://localhost:8080/__admin/gui— assets load, API calls succeedhttp://localhost:8080/wiremock/__admin/guivia a reverse proxy that strips/wiremock— assets load, API calls succeednpm run dev) still works for local developmentMade with Cursor