Skip to content

Commit 9e147dc

Browse files
committed
Add option to override host in displayed url
This commit introduces a new alias `connect-host` to override the host info displayed at launch with a custom string. It is intended to be used when the app is run in an environment where the url to display to the users is not detectable reliably (proxified or containerized setups for example).
1 parent 459b92c commit 9e147dc

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

notebook/notebookapp.py

+16-4
Original file line numberDiff line numberDiff line change
@@ -548,6 +548,7 @@ def start(self):
548548
'notebook-dir': 'NotebookApp.notebook_dir',
549549
'browser': 'NotebookApp.browser',
550550
'pylab': 'NotebookApp.pylab',
551+
'connect-host': 'NotebookApp.connect_host',
551552
})
552553

553554
#-----------------------------------------------------------------------------
@@ -666,6 +667,14 @@ def _valdate_ip(self, proposal):
666667
value = u''
667668
return value
668669

670+
connect_host = Unicode(u'', config=True,
671+
help=_("""Custom host to show in displayed URL.
672+
673+
Replace actual host, including protocol, address, port and base URL,
674+
with the given value when displaying URL to the users. Do not change
675+
the actual connection URL.""")
676+
)
677+
669678
port = Integer(8888, config=True,
670679
help=_("The port the notebook server will listen on.")
671680
)
@@ -1339,11 +1348,14 @@ def init_webapp(self):
13391348

13401349
@property
13411350
def display_url(self):
1342-
if self.ip in ('', '0.0.0.0'):
1343-
ip = socket.gethostname()
1351+
if self.connect_host:
1352+
url = self.connect_host + '/'
13441353
else:
1345-
ip = self.ip
1346-
url = self._url(ip)
1354+
if self.ip in ('', '0.0.0.0'):
1355+
ip = socket.gethostname()
1356+
else:
1357+
ip = self.ip
1358+
url = self._url(ip)
13471359
if self.token:
13481360
# Don't log full token if it came from config
13491361
token = self.token if self._token_generated else '...'

0 commit comments

Comments
 (0)