Skip to content

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

Description

@Slav4ik

Problem

When WireMock GUI is served behind a reverse proxy under a sub-path (e.g. https://host/wiremock/__admin/gui, where the proxy strips the /wiremock prefix before forwarding to WireMock), the GUI fails to load and cannot communicate with the admin API.

This makes the GUI unusable in common deployment patterns (Kubernetes ingress path prefixes, API gateways, shared hosts) unless the deployer forks the project and rebuilds with custom paths.

Root cause

Two places hardcode a root-mount assumption:

1. Static assets (Vite build)

webapp/vite.config.ts sets base: '/__admin/gui/'. Vite bakes that absolute path into the built index.html:

<script src="/__admin/gui/assets/...">
<link href="/__admin/gui/assets/...">

When the page is loaded at https://host/wiremock/__admin/gui, the browser resolves these absolute paths against the host root and requests https://host/__admin/gui/assets/... — the /wiremock prefix is lost, so assets never route back through the proxy to WireMock.

2. API base URL (React app)

webapp/src/App.tsx has getDefaultBaseUrl() which returns window.location.origin (path stripped) whenever window.location.pathname.includes('/__admin'). Every WireMockClient request therefore goes to <origin>/__admin/..., again dropping any sub-path prefix.

Expected behavior

The GUI should work when served at any mount path:

  • Root: https://host/__admin/gui (current behavior, must remain unchanged)
  • Prefixed: https://host/wiremock/__admin/gui (proxy strips prefix; WireMock still sees /__admin/gui)

…with no deploy-time rebuild or fork required.

Proposed fix

  1. Assets: Use relative asset references (e.g. Vite base: './') combined with a runtime <base href> computed from window.location.pathname up to and including /__admin/gui/, injected via a small inline script in index.html before the module script. This ensures ./assets/x.js resolves correctly for both root and prefixed mounts.

  2. API base: In getDefaultBaseUrl(), when the path contains /__admin, derive the base as window.location.origin + <prefix> where <prefix> is window.location.pathname truncated just before /__admin. Example: /wiremock/__admin/gui → API base https://host/wiremock; /__admin/guihttps://host.

Preserve existing localStorage override and http://localhost:8080 fallback.

Impact

  • Enables path-based reverse-proxy deployments without forking
  • Fully backward-compatible for current root-mounted deployments
  • Frontend-only change; no Java/server-side changes required

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions