fix(proxy): serve visdom correctly when accessed via a path-based reverse proxy#978
Open
devs6186 wants to merge 3 commits intofossasia:masterfrom
Open
fix(proxy): serve visdom correctly when accessed via a path-based reverse proxy#978devs6186 wants to merge 3 commits intofossasia:masterfrom
devs6186 wants to merge 3 commits intofossasia:masterfrom
Conversation
…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
- _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).
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.
Description
When visdom is started with
-base_url /path1and accessed through a reverse proxy athttp://proxy:8080/path1, the browser client was constructing socket and API URLs relative towindow.location.pathnamerather 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 passesbase_url=self.base_urltoindex.html(was missing).CompareHandlergainsself.base_urlininitialize()and passes it toindex.html.EnvHandlergainsself.base_urlininitialize()and passes it toindex.html(was completely missing, causing a TornadoKeyErrorfor any/env/<name>URL whenbase_urlwas set).Template —
index.html: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 checksVISDOM_BASE_URLfirst: if it is set and not'/', it returns that value (with a trailing slash). Falls back to the existingwindow.location.pathname-based logic whenbase_urlis the default.ws://host/path1/socketandPOST /path1/env/…are constructed with the correct prefix.Linting —
.eslintrc:VISDOM_BASE_URLadded toglobalsas"readonly"to suppressno-undefwarnings.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).-base_url ""or omitted):VISDOM_BASE_URLis'/',correctPathname()returns'/'— identical to previous behaviour.-base_url /path1: client receives'/path1', socket connects tows://host/path1/socket, API posts go to/path1/env/…./,/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
Checklist:
py/visdom/VERSIONaccording to Semantic Versioning