|
@@ -30,10 +30,24 @@ async def _lifespan(_: App):
|
|
yield
|
|
yield
|
|
await _shutdown()
|
|
await _shutdown()
|
|
|
|
|
|
|
|
+
|
|
|
|
+class SocketIoApp(socketio.ASGIApp):
|
|
|
|
+ """Custom ASGI app to handle root_path.
|
|
|
|
+
|
|
|
|
+ This is a workaround for https://github.com/miguelgrinberg/python-engineio/pull/345
|
|
|
|
+ """
|
|
|
|
+
|
|
|
|
+ async def __call__(self, scope, receive, send):
|
|
|
|
+ root_path = scope.get('root_path')
|
|
|
|
+ if root_path and scope['path'].startswith(root_path):
|
|
|
|
+ scope['path'] = scope['path'][len(root_path):]
|
|
|
|
+ return await super().__call__(scope, receive, send)
|
|
|
|
+
|
|
|
|
+
|
|
core.app = app = App(default_response_class=NiceGUIJSONResponse, lifespan=_lifespan)
|
|
core.app = app = App(default_response_class=NiceGUIJSONResponse, lifespan=_lifespan)
|
|
# NOTE we use custom json module which wraps orjson
|
|
# NOTE we use custom json module which wraps orjson
|
|
core.sio = sio = socketio.AsyncServer(async_mode='asgi', cors_allowed_origins='*', json=json)
|
|
core.sio = sio = socketio.AsyncServer(async_mode='asgi', cors_allowed_origins='*', json=json)
|
|
-sio_app = socketio.ASGIApp(socketio_server=sio, socketio_path='/_nicegui_ws/socket.io')
|
|
|
|
|
|
+sio_app = SocketIoApp(socketio_server=sio, socketio_path='/socket.io')
|
|
app.mount('/_nicegui_ws/', sio_app)
|
|
app.mount('/_nicegui_ws/', sio_app)
|
|
|
|
|
|
|
|
|