33import ssl
44from logging import Logger
55
6+ from jupyter_server .utils import ensure_async
67from jupyterhub import __version__ as __jh_version__
78from jupyterhub .services .auth import HubOAuthCallbackHandler , HubOAuthenticated
89from jupyterhub .utils import make_ssl_context
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,21 @@ 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 ),
152+ (rf"^ { escaped_prefix } $" , RedirectHandler , dict ( url = rf"^ { escaped_prefix } /" ) ),
150153 (
151- r"^" + re . escape ( prefix ) + r" /(.*)" ,
154+ rf"^ { escaped_prefix } /(.*)" ,
152155 Proxy ,
153156 dict (
154157 state = {},
155158 # ToDo: progressive=progressive
156159 ),
157160 ),
158161 (
159- r"^" + re . escape ( prefix ) + r" /oauth_callback" ,
162+ rf"^ { escaped_prefix } /oauth_callback" ,
160163 HubOAuthCallbackHandler ,
161164 ),
162165 ],
0 commit comments