Skip to content

Change port number for JUPYTERHUB_SERVICE_URL #268

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
Closed
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
12 changes: 12 additions & 0 deletions batchspawner/singleuser.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
from jupyterhub.utils import random_port, url_path_join
from jupyterhub.services.auth import HubAuth

from urllib.parse import urlparse, urlunparse

import requests


Expand Down Expand Up @@ -34,6 +36,16 @@ def main(argv=None):
**kwargs,
)

# Change the port number for the environment variable JUPYTERHUB_SERVICE_URL
url = urlparse(os.environ["JUPYTERHUB_SERVICE_URL"])
url_netloc = url.netloc.split(":")

if len(url_netloc) == 2:
Copy link

Choose a reason for hiding this comment

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

This method of setting the port would lead to the new port not being set if the netloc in the original JUPYTERHUB_SERVICE_URL doesn't have the port explicitly defined (e.g. https://example.com/test wouldn't change). Meanwhile the solution in PR #267 for this issue does replace the port in all cases.

url_netloc[1] = str(port)
os.environ["JUPYTERHUB_SERVICE_URL"] = urlunparse(
url._replace(netloc=":".join(url_netloc))
)

cmd_path = which(sys.argv[1])
sys.argv = sys.argv[1:] + ["--port={}".format(port)]
run_path(cmd_path, run_name="__main__")
Expand Down