Falko Schindler преди 2 години
родител
ревизия
6df4fd63c1
променени са 4 файла, в които са добавени 11 реда и са изтрити 11 реда
  1. 1 2
      nicegui/client.py
  2. 7 7
      nicegui/nicegui.py
  3. 1 1
      nicegui/page.py
  4. 2 1
      nicegui/templates/index.html

+ 1 - 2
nicegui/client.py

@@ -21,8 +21,7 @@ TEMPLATE = (Path(__file__).parent / 'templates' / 'index.html').read_text()
 
 class Client:
 
-    def __init__(self, page: 'page', *, request: Optional[Request] = None, shared: bool = False) -> None:
-        self.request = request
+    def __init__(self, page: 'page', *, shared: bool = False) -> None:
         self.id = globals.next_client_id
         globals.next_client_id += 1
         globals.clients[self.id] = self

+ 7 - 7
nicegui/nicegui.py

@@ -36,7 +36,7 @@ def index(request: Request) -> str:
 def vue_dependencies(path: str):
     if Path(path).exists():
         return FileResponse(path, media_type='text/javascript')
-    return HTTPException(status_code=404, detail="{path} not found")
+    return HTTPException(status_code=404, detail='{path} not found')
 
 
 @app.get('/_vue/components/{name}')
@@ -64,19 +64,19 @@ def shutdown() -> None:
 
 
 @app.exception_handler(404)
-async def exception_handler(r: Request, exception: Exception):
-    globals.log.warning(f'{r.url} not found')
+async def exception_handler(request: Request, exception: Exception):
+    globals.log.warning(f'{request.url} not found')
     with Client(page('')) as client:
         error_content(404, exception)
-    return client.build_response(r, 404)
+    return client.build_response(request, 404)
 
 
 @app.exception_handler(Exception)
-async def exception_handler(r: Request, exception: Exception):
-    globals.log.exception(f'unexpected exception for {r.url}', exception)
+async def exception_handler(request: Request, exception: Exception):
+    globals.log.exception(f'unexpected exception for {request.url}', exception)
     with Client(page('')) as client:
         error_content(500, exception)
-    return client.build_response(r, 500)
+    return client.build_response(request, 500)
 
 
 @sio.on('connect')

+ 1 - 1
nicegui/page.py

@@ -53,7 +53,7 @@ class page:
             request = dec_kwargs['request']
             # NOTE cleaning up the keyword args so the signature is consistent with "func" again
             dec_kwargs = {k: v for k, v in dec_kwargs.items() if k in parameters_of_decorated_func}
-            with Client(self, request=request) as client:
+            with Client(self) as client:
                 if any(p.name == 'client' for p in inspect.signature(func).parameters.values()):
                     dec_kwargs['client'] = client
                 result = func(*dec_args, **dec_kwargs)

+ 2 - 1
nicegui/templates/index.html

@@ -78,7 +78,8 @@
         },
         mounted() {
           const query = { client_id: {{ client_id }} };
-          window.socket = io(window.location.protocol === 'https:' ? 'wss://' : 'ws://' + window.location.host, { path: "{{ prefix | safe }}/ws/socket.io", query: query });
+          const url = window.location.protocol === 'https:' ? 'wss://' : 'ws://' + window.location.host;
+          window.socket = io(url, { path: "{{ prefix | safe }}/ws/socket.io", query });
           window.socket.on("update", (msg) => {
             Object.entries(msg.elements).forEach(([id, element]) => this.elements[element.id] = element);
           });