Skip to content

Commit 2bad812

Browse files
authored
Merge pull request #3668 from tomjorquera/connect_host
Add option to override host in displayed url
2 parents e7771ba + 24e39d3 commit 2bad812

File tree

1 file changed

+22
-4
lines changed

1 file changed

+22
-4
lines changed

notebook/notebookapp.py

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -666,6 +666,19 @@ def _valdate_ip(self, proposal):
666666
value = u''
667667
return value
668668

669+
custom_display_url = Unicode(u'', config=True,
670+
help=_("""Override URL shown to users.
671+
672+
Replace actual URL, including protocol, address, port and base URL,
673+
with the given value when displaying URL to the users. Do not change
674+
the actual connection URL. If authentication token is enabled, the
675+
token is added to the custom URL automatically.
676+
677+
This option is intended to be used when the URL to display to the user
678+
cannot be determined reliably by the Jupyter notebook server (proxified
679+
or containerized setups for example).""")
680+
)
681+
669682
port = Integer(8888, config=True,
670683
help=_("The port the notebook server will listen on.")
671684
)
@@ -1339,11 +1352,16 @@ def init_webapp(self):
13391352

13401353
@property
13411354
def display_url(self):
1342-
if self.ip in ('', '0.0.0.0'):
1343-
ip = socket.gethostname()
1355+
if self.custom_display_url:
1356+
url = self.custom_display_url
1357+
if not url.endswith('/'):
1358+
url += '/'
13441359
else:
1345-
ip = self.ip
1346-
url = self._url(ip)
1360+
if self.ip in ('', '0.0.0.0'):
1361+
ip = socket.gethostname()
1362+
else:
1363+
ip = self.ip
1364+
url = self._url(ip)
13471365
if self.token:
13481366
# Don't log full token if it came from config
13491367
token = self.token if self._token_generated else '...'

0 commit comments

Comments
 (0)