mirror of
https://github.com/jupyterhub/jupyterhub.git
synced 2025-10-16 14:33:00 +00:00
add URLPrefix traitlet
ensures leading, trailing /
This commit is contained in:
@@ -44,6 +44,7 @@ from . import handlers, apihandlers
|
|||||||
|
|
||||||
from . import orm
|
from . import orm
|
||||||
from ._data import DATA_FILES_PATH
|
from ._data import DATA_FILES_PATH
|
||||||
|
from .traitlets import URLPrefix
|
||||||
from .utils import (
|
from .utils import (
|
||||||
url_path_join,
|
url_path_join,
|
||||||
ISO8601_ms, ISO8601_s,
|
ISO8601_ms, ISO8601_s,
|
||||||
@@ -55,6 +56,7 @@ from .spawner import Spawner, LocalProcessSpawner
|
|||||||
aliases = {
|
aliases = {
|
||||||
'log-level': 'Application.log_level',
|
'log-level': 'Application.log_level',
|
||||||
'f': 'JupyterHubApp.config_file',
|
'f': 'JupyterHubApp.config_file',
|
||||||
|
'base-url': 'JupyterHubApp.base_url',
|
||||||
'config': 'JupyterHubApp.config_file',
|
'config': 'JupyterHubApp.config_file',
|
||||||
'y': 'JupyterHubApp.answer_yes',
|
'y': 'JupyterHubApp.answer_yes',
|
||||||
'ssl-key': 'JupyterHubApp.ssl_key',
|
'ssl-key': 'JupyterHubApp.ssl_key',
|
||||||
@@ -153,10 +155,11 @@ class JupyterHubApp(Application):
|
|||||||
port = Integer(8000, config=True,
|
port = Integer(8000, config=True,
|
||||||
help="The public facing port of the proxy"
|
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"
|
help="The base URL of the entire application"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
jinja_environment_options = Dict(config=True,
|
jinja_environment_options = Dict(config=True,
|
||||||
help="Supply extra arguments that will be passed to Jinja environment."
|
help="Supply extra arguments that will be passed to Jinja environment."
|
||||||
)
|
)
|
||||||
@@ -201,7 +204,7 @@ class JupyterHubApp(Application):
|
|||||||
help="The ip for this process"
|
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 '/'"
|
help="The prefix for the hub server. Must not be '/'"
|
||||||
)
|
)
|
||||||
def _hub_prefix_default(self):
|
def _hub_prefix_default(self):
|
||||||
@@ -210,15 +213,8 @@ class JupyterHubApp(Application):
|
|||||||
def _hub_prefix_changed(self, name, old, new):
|
def _hub_prefix_changed(self, name, old, new):
|
||||||
if new == '/':
|
if new == '/':
|
||||||
raise TraitError("'/' is not a valid hub prefix")
|
raise TraitError("'/' is not a valid hub prefix")
|
||||||
newnew = new
|
if not new.startswith(self.base_url):
|
||||||
if not new.startswith('/'):
|
self.hub_prefix = url_path_join(self.base_url, new)
|
||||||
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
|
|
||||||
|
|
||||||
cookie_secret = Bytes(config=True, env='JPY_COOKIE_SECRET',
|
cookie_secret = Bytes(config=True, env='JPY_COOKIE_SECRET',
|
||||||
help="""The cookie secret to use to encrypt cookies.
|
help="""The cookie secret to use to encrypt cookies.
|
||||||
|
14
jupyterhub/traitlets.py
Normal file
14
jupyterhub/traitlets.py
Normal file
@@ -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
|
Reference in New Issue
Block a user