mirror of
https://github.com/jupyterhub/jupyterhub.git
synced 2025-10-10 19:43:01 +00:00
raise warning if PUBLIC_HOST is not set
This commit is contained in:
@@ -1,16 +1,31 @@
|
|||||||
import os
|
import os
|
||||||
|
import warnings
|
||||||
|
|
||||||
service = {
|
# When Swagger performs OAuth2 in the browser, it will set
|
||||||
"name": "fastapi",
|
# the request host + relative path as the redirect uri, causing a
|
||||||
"url": "http://127.0.0.1:10202",
|
# uri mismatch if the oauth_redirect_uri is just the relative path
|
||||||
"command": ["uvicorn", "app:app", "--port", "10202"],
|
# is set in the c.JupyterHub.services entry (as per default).
|
||||||
}
|
# Therefore need to know the request host ahead of time.
|
||||||
# If running behind a proxy, or in Docker / Kubernetes infrastructure,
|
if "PUBLIC_HOST" not in os.environ:
|
||||||
# you probably need to set a different public Hub host than the
|
msg = (
|
||||||
# internal JUPYTERHUB_API_URL host
|
"env PUBLIC_HOST is not set, defaulting to http://127.0.0.1:8000. "
|
||||||
if "PUBLIC_HOST" in os.environ:
|
"This can cause problems with OAuth. "
|
||||||
public_host = os.environ["PUBLIC_HOST"]
|
"Set PUBLIC_HOST to your public (browser accessible) host."
|
||||||
service["oauth_redirect_uri"] = f"{public_host}/services/fastapi/oauth_callback"
|
)
|
||||||
service["environment"] = {"PUBLIC_HOST": public_host}
|
warnings.warn(msg)
|
||||||
|
public_host = "http://127.0.0.1:8000"
|
||||||
|
else:
|
||||||
|
public_host = os.environ["PUBLIC_HOST"].rstrip('/')
|
||||||
|
service_name = "fastapi"
|
||||||
|
oauth_redirect_uri = f"{public_host}/services/{service_name}/oauth_callback"
|
||||||
|
|
||||||
c.JupyterHub.services = [service]
|
c.JupyterHub.services = [
|
||||||
|
{
|
||||||
|
"name": service_name,
|
||||||
|
"url": "http://127.0.0.1:10202",
|
||||||
|
"command": ["uvicorn", "app:app", "--port", "10202"],
|
||||||
|
"admin": True,
|
||||||
|
"oauth_redirect_uri": oauth_redirect_uri,
|
||||||
|
"environment": {"PUBLIC_HOST": public_host},
|
||||||
|
}
|
||||||
|
]
|
||||||
|
Reference in New Issue
Block a user