66from jupyterhub import __version__ as __jh_version__
77from jupyterhub .services .auth import HubOAuthCallbackHandler , HubOAuthenticated
88from jupyterhub .utils import make_ssl_context
9+ from jupyter_server .utils import ensure_async
910from tornado import httpclient , web
1011from tornado .log import app_log
11- from tornado .web import Application
12+ from tornado .web import Application , RedirectHandler
1213from tornado .websocket import WebSocketHandler
1314
14- from ..handlers import AddSlashHandler , SuperviseAndProxyHandler
15+ from ..handlers import SuperviseAndProxyHandler
1516
1617
1718class StandaloneHubProxyHandler (HubOAuthenticated , SuperviseAndProxyHandler ):
@@ -52,7 +53,7 @@ async def proxy(self, port, path):
5253 if self .skip_authentication :
5354 return await super ().proxy (port , path )
5455 else :
55- return await self .oauth_proxy (port , path )
56+ return await ensure_async ( self .oauth_proxy (port , path ) )
5657
5758 @web .authenticated
5859 async def oauth_proxy (self , port , path ):
@@ -133,6 +134,7 @@ def __init__(self, *args, **kwargs):
133134
134135 settings = dict (
135136 debug = debug ,
137+ base_url = prefix ,
136138 # Required for JupyterHub
137139 hub_user = os .environ .get ("JUPYTERHUB_USER" , "" ),
138140 hub_group = os .environ .get ("JUPYTERHUB_GROUP" , "" ),
@@ -143,20 +145,27 @@ def __init__(self, *args, **kwargs):
143145 app_log .debug (f"Restricting WebSocket Messages to { websocket_max_message_size } " )
144146 settings ["websocket_max_message_size" ] = websocket_max_message_size
145147
148+ escaped_prefix = re .escape (prefix )
146149 app = Application (
147150 [
148151 # Redirects from the JupyterHub might not contain a slash
149- (r"^" + re .escape (prefix ) + r"$" , AddSlashHandler ),
150152 (
151- r"^" + re .escape (prefix ) + r"/(.*)" ,
153+ rf"^{ escaped_prefix } $" ,
154+ RedirectHandler ,
155+ dict (
156+ url = rf"^{ escaped_prefix } /"
157+ )
158+ ),
159+ (
160+ rf"^{ escaped_prefix } /(.*)" ,
152161 Proxy ,
153162 dict (
154163 state = {},
155164 # ToDo: progressive=progressive
156165 ),
157166 ),
158167 (
159- r"^" + re . escape ( prefix ) + r" /oauth_callback" ,
168+ rf"^ { escaped_prefix } /oauth_callback" ,
160169 HubOAuthCallbackHandler ,
161170 ),
162171 ],
0 commit comments