Skip to content

Allow to have multiple desktop endpoints, and relocate the endpoint #158

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,13 @@ function status(text) {
document.getElementById("status").textContent = text;
}

// This page is served under the /desktop/, and the websockify websocket is served
// under /desktop-websockify/ with the same base url as /desktop/. We resolve it relatively
// This page is served under the /desktopvnc/, and the websockify websocket is served
// under /desktop/ with the same base url as /desktopvnc/. We resolve it relatively
// this way.
let websockifyUrl = new URL("../desktop-websockify/", window.location);
let websockifyUrl = new URL(
window.location.pathname.replace(/vnc\/+$/, "/"),
window.location,
);
websockifyUrl.protocol = window.location.protocol === "https:" ? "wss" : "ws";

let retryCount = 0;
Expand Down
34 changes: 19 additions & 15 deletions jupyter_remote_desktop_proxy/server_extension.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import os
from pathlib import Path

from jupyter_server.base.handlers import AuthenticatedFileHandler
Expand All @@ -15,18 +16,21 @@ def load_jupyter_server_extension(server_app):
"""
base_url = server_app.web_app.settings["base_url"]

server_app.web_app.add_handlers(
".*",
[
# Serve our own static files
(
url_path_join(base_url, "/desktop/static/(.*)"),
AuthenticatedFileHandler,
{"path": (str(HERE / "static"))},
),
# To simplify URL mapping, we make sure that /desktop/ always
# has a trailing slash
(url_path_join(base_url, "/desktop"), AddSlashHandler),
(url_path_join(base_url, "/desktop/"), DesktopHandler),
],
)
jupyter_remote_desktop_endpoints = os.getenv('JUPYTER_REMOTE_DESKTOP_ENDPOINTS', '')
endpoints = ['desktop'] + jupyter_remote_desktop_endpoints.split(',')
for endpoint in endpoints:
server_app.web_app.add_handlers(
".*",
[
# Serve our own static files
(
url_path_join(base_url, f"/{endpoint}vnc/static/(.*)"),
AuthenticatedFileHandler,
{"path": (str(HERE / "static"))},
),
# To simplify URL mapping, we make sure that /desktop/ always
# has a trailing slash
(url_path_join(base_url, f"/{endpoint}vnc"), AddSlashHandler),
(url_path_join(base_url, f"/{endpoint}vnc/"), DesktopHandler),
],
)
6 changes: 3 additions & 3 deletions jupyter_remote_desktop_proxy/setup_websockify.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,10 @@ def setup_websockify():
'command': ['/bin/sh', '-c', f'cd {os.getcwd()} && {vnc_command}'],
'timeout': 30,
'new_browser_window': True,
# We want the launcher entry to point to /desktop/, not to /desktop-websockify/
# /desktop/ is the user facing URL, while /desktop-websockify/ now *only* serves
# We want the launcher entry to point to /desktopvnc/, not to /desktop/
# /desktop/ is the user facing URL, while /desktop/ now *only* serves
# websockets.
"launcher_entry": {"title": "Desktop", "path_info": "desktop"},
"launcher_entry": {"title": "Desktop", "path_info": "desktopvnc"},
"unix_socket": True,
"raw_socket_proxy": True,
}
9 changes: 6 additions & 3 deletions jupyter_remote_desktop_proxy/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,16 @@
Chrome Frame. -->
<meta http-equiv="X-UA-Compatible" content="IE=edge" />

<link href="{{ base_url }}desktop/static/dist/index.css" rel="stylesheet" />
<link
href="{{ base_url }}desktopvnc/static/dist/index.css"
rel="stylesheet"
/>
</head>

<body>
<div id="top-bar">
<a href=".." id="logo">
<img src="{{base_url}}desktop/static/jupyter-logo.svg" />
<img src="{{base_url}}desktopvnc/static/jupyter-logo.svg" />
</a>
<ul id="menu">
<li id="status-container">
Expand Down Expand Up @@ -52,6 +55,6 @@
</div>
</div>

<script src="{{base_url}}desktop/static/dist/viewer.js"></script>
<script src="{{base_url}}desktopvnc/static/dist/viewer.js"></script>
</body>
</html>
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def run(self):
description="Run a desktop environments on Jupyter",
entry_points={
'jupyter_serverproxy_servers': [
'desktop-websockify = jupyter_remote_desktop_proxy.setup_websockify:setup_websockify',
'desktop = jupyter_remote_desktop_proxy.setup_websockify:setup_websockify',
]
},
install_requires=[
Expand Down
2 changes: 1 addition & 1 deletion tests/test_browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def test_desktop(browser):
with page.expect_popup() as page1_info:
page.get_by_text("Desktop [↗]").click()
page1 = page1_info.value
page1.wait_for_url(f"{JUPYTER_HOST}/desktop/")
page1.wait_for_url(f"{JUPYTER_HOST}/desktopvnc/")

expect(page1.get_by_text("Status: Connected")).to_be_visible()
expect(page1.locator("canvas")).to_be_visible()
Expand Down