From 47b4f1199ad91046008d8c3e551a086d0dc0ccd2 Mon Sep 17 00:00:00 2001 From: Simon Li Date: Sat, 2 Nov 2019 15:37:35 +0000 Subject: [PATCH] allow different internal and public hub_url --- binderhub/app.py | 11 ++++++++++- binderhub/launcher.py | 3 ++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/binderhub/app.py b/binderhub/app.py index 8607fecb6b..1f6a90ae56 100644 --- a/binderhub/app.py +++ b/binderhub/app.py @@ -352,7 +352,15 @@ def _default_hub_token(self): """, config=True, ) - @validate('hub_url') + + hub_url_public = Unicode( + help=""" + The public base URL of the JupyterHub instance where users will run if different from hub_url + """, + config=True, + ) + + @validate('hub_url', 'hub_url_public') def _add_slash(self, proposal): """trait validator to ensure hub_url ends with a trailing slash""" if proposal.value is not None and not proposal.value.endswith('/'): @@ -549,6 +557,7 @@ def initialize(self, *args, **kwargs): self.launcher = Launcher( parent=self, hub_url=self.hub_url, + hub_url_public=self.hub_url_public, hub_api_token=self.hub_api_token, create_user=not self.auth_enabled, ) diff --git a/binderhub/launcher.py b/binderhub/launcher.py index ce0b8e70a3..61d6f35338 100644 --- a/binderhub/launcher.py +++ b/binderhub/launcher.py @@ -32,6 +32,7 @@ class Launcher(LoggingConfigurable): hub_api_token = Unicode(help="The API token for the Hub") hub_url = Unicode(help="The URL of the Hub") + hub_url_public = Unicode(help="The public URL of the Hub if different") create_user = Bool(True, help="Create a new Hub user") retries = Integer( 4, @@ -196,5 +197,5 @@ async def launch(self, image, username, server_name='', repo_url=''): format(_server_name, username, e, body)) raise web.HTTPError(500, "Failed to launch image %s" % image) - data['url'] = self.hub_url + 'user/%s/%s' % (username, server_name) + data['url'] = (self.hub_url_public or self.hub_url) + 'user/%s/%s' % (username, server_name) return data