3
3
import ssl
4
4
from logging import Logger
5
5
6
+ from jupyter_server .utils import ensure_async
6
7
from jupyterhub import __version__ as __jh_version__
7
8
from jupyterhub .services .auth import HubOAuthCallbackHandler , HubOAuthenticated
8
9
from jupyterhub .utils import make_ssl_context
9
10
from tornado import httpclient , web
10
11
from tornado .log import app_log
11
- from tornado .web import Application
12
+ from tornado .web import Application , RedirectHandler
12
13
from tornado .websocket import WebSocketHandler
13
14
14
- from ..handlers import AddSlashHandler , SuperviseAndProxyHandler
15
+ from ..handlers import SuperviseAndProxyHandler
15
16
16
17
17
18
class StandaloneHubProxyHandler (HubOAuthenticated , SuperviseAndProxyHandler ):
@@ -52,7 +53,7 @@ async def proxy(self, port, path):
52
53
if self .skip_authentication :
53
54
return await super ().proxy (port , path )
54
55
else :
55
- return await self .oauth_proxy (port , path )
56
+ return await ensure_async ( self .oauth_proxy (port , path ) )
56
57
57
58
@web .authenticated
58
59
async def oauth_proxy (self , port , path ):
@@ -133,6 +134,7 @@ def __init__(self, *args, **kwargs):
133
134
134
135
settings = dict (
135
136
debug = debug ,
137
+ base_url = prefix ,
136
138
# Required for JupyterHub
137
139
hub_user = os .environ .get ("JUPYTERHUB_USER" , "" ),
138
140
hub_group = os .environ .get ("JUPYTERHUB_GROUP" , "" ),
@@ -143,20 +145,21 @@ def __init__(self, *args, **kwargs):
143
145
app_log .debug (f"Restricting WebSocket Messages to { websocket_max_message_size } " )
144
146
settings ["websocket_max_message_size" ] = websocket_max_message_size
145
147
148
+ escaped_prefix = re .escape (prefix )
146
149
app = Application (
147
150
[
148
151
# 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 } /" ) ),
150
153
(
151
- r"^" + re . escape ( prefix ) + r" /(.*)" ,
154
+ rf"^ { escaped_prefix } /(.*)" ,
152
155
Proxy ,
153
156
dict (
154
157
state = {},
155
158
# ToDo: progressive=progressive
156
159
),
157
160
),
158
161
(
159
- r"^" + re . escape ( prefix ) + r" /oauth_callback" ,
162
+ rf"^ { escaped_prefix } /oauth_callback" ,
160
163
HubOAuthCallbackHandler ,
161
164
),
162
165
],
0 commit comments