Skip to content

fix(proxy): serve visdom correctly when accessed via a path-based reverse proxy#978

Open
devs6186 wants to merge 3 commits intofossasia:masterfrom
devs6186:fix/666-proxy-base-url
Open

fix(proxy): serve visdom correctly when accessed via a path-based reverse proxy#978
devs6186 wants to merge 3 commits intofossasia:masterfrom
devs6186:fix/666-proxy-base-url

Conversation

@devs6186
Copy link

Description

When visdom is started with -base_url /path1 and accessed through a reverse proxy at http://proxy:8080/path1, the browser client was constructing socket and API URLs relative to window.location.pathname rather than the server-configured base path. This broke the WebSocket handshake and all subsequent API calls.

This PR implements full proxy support across three layers:

Backend — web_handlers.py:

  • IndexHandler.get() now passes base_url=self.base_url to index.html (was missing).
  • CompareHandler gains self.base_url in initialize() and passes it to index.html.
  • EnvHandler gains self.base_url in initialize() and passes it to index.html (was completely missing, causing a Tornado KeyError for any /env/<name> URL when base_url was set).

Template — index.html:

  • Added var VISDOM_BASE_URL = '{{escape(base_url)}}'; so the server-configured path is available to client-side JS.

Frontend — js/api/ApiProvider.js:

  • correctPathname() now checks VISDOM_BASE_URL first: if it is set and not '/', it returns that value (with a trailing slash). Falls back to the existing window.location.pathname-based logic when base_url is the default.
  • This ensures ws://host/path1/socket and POST /path1/env/… are constructed with the correct prefix.

Linting — .eslintrc:

  • VISDOM_BASE_URL added to globals as "readonly" to suppress no-undef warnings.

Motivation and Context

Fixes #666. Visdom was completely broken when served under any sub-path prefix via a reverse proxy (nginx, Caddy, Jupyter Server Proxy, etc.).

How Has This Been Tested?

  • python -m py_compile py/visdom/server/handlers/web_handlers.py — clean.
  • python -m black --check py — clean.
  • npm run lint — clean (VISDOM_BASE_URL declared in globals).
  • Manually verified:
    • Default launch (-base_url "" or omitted): VISDOM_BASE_URL is '/', correctPathname() returns '/' — identical to previous behaviour.
    • With -base_url /path1: client receives '/path1', socket connects to ws://host/path1/socket, API posts go to /path1/env/….
    • All three entry points (/, /env/<name>, /compare/<ids>) render without errors.

Screenshots (if appropriate):

N/A — connection-layer fix; no visible UI change for default deployments.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)

Checklist:

  • I adapted the version number under py/visdom/VERSION according to Semantic Versioning
  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.

…roxy

EnvHandler.get() renders index.html but was the only handler that did
not supply the base_url template variable.  After the earlier commit
that added VISDOM_BASE_URL to index.html, any request routed through
EnvHandler (e.g. /path1/env/main) would raise a Tornado KeyError
because the variable was undefined.

Fix: add self.base_url initialisation to EnvHandler.initialize()
and pass base_url=self.base_url to the render() call, matching the
pattern already used by IndexHandler and CompareHandler.

Fixes remaining breakage from fossasia#666
Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry @devs6186, you have reached your weekly rate limit of 500000 diff characters.

Please try again later or upgrade to continue using Sourcery

- _markerColorCheck: add explicit palette bounds check before indexing.
  Labels are 1-based so the effective index is Y[i]-1; assert
  (Y-1).max() < mc.shape[0] prevents out-of-bounds access and gives a
  clear error message when violated.
- ApiProvider: extract getNormalizedBaseUrl() helper to normalise
  VISDOM_BASE_URL once, removing the repeated undefined/empty/'/'
  branches from correctPathname() and making the precedence explicit.
- Apply black formatting to py/visdom/__init__.py (pre-existing style).
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.

Visdom does not display when accessed via a proxy (with a path in its URL)

1 participant