diff --git a/jupyterhub/app.py b/jupyterhub/app.py index 1ad573ee..44974282 100644 --- a/jupyterhub/app.py +++ b/jupyterhub/app.py @@ -44,6 +44,7 @@ from . import handlers, apihandlers from . import orm from ._data import DATA_FILES_PATH +from .traitlets import URLPrefix from .utils import ( url_path_join, ISO8601_ms, ISO8601_s, @@ -55,6 +56,7 @@ from .spawner import Spawner, LocalProcessSpawner aliases = { 'log-level': 'Application.log_level', 'f': 'JupyterHubApp.config_file', + 'base-url': 'JupyterHubApp.base_url', 'config': 'JupyterHubApp.config_file', 'y': 'JupyterHubApp.answer_yes', 'ssl-key': 'JupyterHubApp.ssl_key', @@ -153,10 +155,11 @@ class JupyterHubApp(Application): port = Integer(8000, config=True, help="The public facing port of the proxy" ) - base_url = Unicode('/', config=True, + base_url = URLPrefix('/', config=True, help="The base URL of the entire application" ) + jinja_environment_options = Dict(config=True, help="Supply extra arguments that will be passed to Jinja environment." ) @@ -201,7 +204,7 @@ class JupyterHubApp(Application): help="The ip for this process" ) - hub_prefix = Unicode('/hub/', config=True, + hub_prefix = URLPrefix('/hub/', config=True, help="The prefix for the hub server. Must not be '/'" ) def _hub_prefix_default(self): @@ -210,15 +213,8 @@ class JupyterHubApp(Application): def _hub_prefix_changed(self, name, old, new): if new == '/': raise TraitError("'/' is not a valid hub prefix") - newnew = new - if not new.startswith('/'): - newnew = '/' + new - if not newnew.endswith('/'): - newnew = newnew + '/' - if not newnew.startswith(self.base_url): - newnew = url_path_join(self.base_url, newnew) - if newnew != new: - self.hub_prefix = newnew + if not new.startswith(self.base_url): + self.hub_prefix = url_path_join(self.base_url, new) cookie_secret = Bytes(config=True, env='JPY_COOKIE_SECRET', help="""The cookie secret to use to encrypt cookies. diff --git a/jupyterhub/traitlets.py b/jupyterhub/traitlets.py new file mode 100644 index 00000000..5fe8449f --- /dev/null +++ b/jupyterhub/traitlets.py @@ -0,0 +1,14 @@ +"""extra traitlets""" +# Copyright (c) IPython Development Team. +# Distributed under the terms of the Modified BSD License. + +from IPython.utils.traitlets import Unicode + +class URLPrefix(Unicode): + def validate(self, obj, value): + u = super().validate(obj, value) + if not u.startswith('/'): + u = '/' + u + if not u.endswith('/'): + u = u + '/' + return u