Skip to content

Allow localtileserver prefix override and fix inferred prefix on JH#1314

Merged
giswqs merged 3 commits intoopengeos:masterfrom
jbachus:fix-jhub-localtileserver-prefix
Apr 1, 2026
Merged

Allow localtileserver prefix override and fix inferred prefix on JH#1314
giswqs merged 3 commits intoopengeos:masterfrom
jbachus:fix-jhub-localtileserver-prefix

Conversation

@jbachus
Copy link
Copy Markdown
Contributor

@jbachus jbachus commented Mar 31, 2026

Since JUPYTERHUB_SERVICE_PREFIX includes a trailing slash, LOCALTILESERVER_CLIENT_PREFIX included a double slash in the URL, causing localtileserver requests for JupyterHub to break.

In addition, the current code made it impossible to override LOCALTILESERVER_CLIENT_PREFIX if any of the other conditions matched. Now, it will only override if it's unset.

Copilot AI review requested due to automatic review settings March 31, 2026 23:01
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR updates leafmap.common.get_local_tile_layer() to better handle localtileserver URL prefixing in hosted notebook environments (notably JupyterHub), preventing malformed proxy URLs and allowing user-defined overrides to take precedence.

Changes:

  • Only sets LOCALTILESERVER_CLIENT_PREFIX when it is not already defined in the environment.
  • Adjusts the JupyterHub-derived prefix formatting to avoid producing //proxy/... URLs when JUPYTERHUB_SERVICE_PREFIX includes a trailing slash.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread leafmap/common.py Outdated
Comment thread leafmap/common.py Outdated
Comment thread leafmap/common.py Outdated
Comment on lines +3319 to +3335
# Only override LOCALTILESERVER_CLIENT_PREFIX if it's unset
if os.environ.get("LOCALTILESERVER_CLIENT_PREFIX") is None:
# Make it compatible with binder and JupyterHub
if os.environ.get("JUPYTERHUB_SERVICE_PREFIX") is not None:
os.environ["LOCALTILESERVER_CLIENT_PREFIX"] = (
f"{os.environ['JUPYTERHUB_SERVICE_PREFIX'].lstrip('/')}proxy/{{port}}"
)

if is_studio_lab():
os.environ["LOCALTILESERVER_CLIENT_PREFIX"] = (
f"studiolab/default/jupyter/proxy/{{port}}"
)
elif is_on_aws():
os.environ["LOCALTILESERVER_CLIENT_PREFIX"] = "proxy/{port}"
elif "prefix" in kwargs:
os.environ["LOCALTILESERVER_CLIENT_PREFIX"] = kwargs["prefix"]
kwargs.pop("prefix")
if is_studio_lab():
os.environ["LOCALTILESERVER_CLIENT_PREFIX"] = (
f"studiolab/default/jupyter/proxy/{{port}}"
)
elif is_on_aws():
os.environ["LOCALTILESERVER_CLIENT_PREFIX"] = "proxy/{port}"
elif "prefix" in kwargs:
os.environ["LOCALTILESERVER_CLIENT_PREFIX"] = kwargs["prefix"]
kwargs.pop("prefix")
Copy link

Copilot AI Mar 31, 2026

Choose a reason for hiding this comment

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

This change alters how LOCALTILESERVER_CLIENT_PREFIX is inferred/overridden (including JupyterHub JUPYTERHUB_SERVICE_PREFIX normalization and honoring pre-set values). There are existing unit tests for leafmap.common (e.g., tests/test_common.py), but none cover this prefix-selection behavior; adding focused tests for the env-var combinations would help prevent regressions (double-slash, missing-slash, and ensuring a pre-set prefix isn’t overwritten).

Copilot uses AI. Check for mistakes.
@giswqs giswqs merged commit 62c3c8e into opengeos:master Apr 1, 2026
15 of 16 checks passed
@jbachus jbachus deleted the fix-jhub-localtileserver-prefix branch April 1, 2026 16:11
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.

3 participants