Bläddra i källkod

using non-default socket.io path
This allows easier embedding in other FastAPI apps

Rodja Trappe 2 år sedan
förälder
incheckning
fc9b5421cb
2 ändrade filer med 3 tillägg och 2 borttagningar
  1. 2 1
      nicegui/nicegui.py
  2. 1 1
      nicegui/templates/index.html

+ 2 - 1
nicegui/nicegui.py

@@ -23,7 +23,8 @@ from .helpers import safe_invoke
 from .page import page
 from .page import page
 
 
 globals.app = app = App(default_response_class=NiceGUIJSONResponse)
 globals.app = app = App(default_response_class=NiceGUIJSONResponse)
-socket_manager = SocketManager(app=app, json=json)  # custom json module (wraps orjson)
+# NOTE we use custom json module which wraps orjson
+socket_manager = SocketManager(app=app, mount_location='/_nicegui_ws/', json=json)
 globals.sio = sio = app.sio
 globals.sio = sio = app.sio
 
 
 app.add_middleware(GZipMiddleware)
 app.add_middleware(GZipMiddleware)

+ 1 - 1
nicegui/templates/index.html

@@ -112,7 +112,7 @@
           const url = window.location.protocol === 'https:' ? 'wss://' : 'ws://' + window.location.host;
           const url = window.location.protocol === 'https:' ? 'wss://' : 'ws://' + window.location.host;
           const extraHeaders = {{ socket_io_js_extra_headers | safe }};
           const extraHeaders = {{ socket_io_js_extra_headers | safe }};
           window.path_prefix = "{{ prefix | safe }}";
           window.path_prefix = "{{ prefix | safe }}";
-          window.socket = io(url, { path: "{{ prefix | safe }}/ws/socket.io", query, extraHeaders });
+          window.socket = io(url, { path: "{{ prefix | safe }}/_nicegui_ws/socket.io", query, extraHeaders });
           window.socket.on("connect", () => {
           window.socket.on("connect", () => {
             window.socket.emit("handshake", (ok) => {
             window.socket.emit("handshake", (ok) => {
               if (!ok) window.location.reload();
               if (!ok) window.location.reload();