Browse Source

code review

Falko Schindler 1 year ago
parent
commit
1b21723ea8
4 changed files with 8 additions and 8 deletions
  1. 5 4
      main.py
  2. 1 2
      nicegui/client.py
  3. 1 1
      nicegui/globals.py
  4. 1 1
      nicegui/templates/index.html

+ 5 - 4
main.py

@@ -55,15 +55,16 @@ async def redirect_reference_to_documentation(request: Request,
         return RedirectResponse('/documentation')
     return await call_next(request)
 
-# NOTE in our global fly.io deployment we need to make sure that we connect back to the same instance.
+# NOTE In our global fly.io deployment we need to make sure that we connect back to the same instance.
 fly_instance_id = os.environ.get('FLY_ALLOC_ID', 'local').split('-')[0]
-nicegui_globals.socket_io_js_extra_headers['fly-force-instance-id'] = fly_instance_id  # for http long polling
+nicegui_globals.socket_io_js_extra_headers['fly-force-instance-id'] = fly_instance_id  # for HTTP long polling
 nicegui_globals.socket_io_js_query_params['fly_instance_id'] = fly_instance_id  # for websocket (FlyReplayMiddleware)
 
 
 class FlyReplayMiddleware(BaseHTTPMiddleware):
-    """
-    If the wrong instance was picked by the fly.io load balancer we use the fly-replay header
+    """Replay to correct fly.io instance.
+
+    If the wrong instance was picked by the fly.io load balancer, we use the fly-replay header
     to repeat the request again on the right instance.
 
     This only works if the correct instance is provided as a query_string parameter.

+ 1 - 2
nicegui/client.py

@@ -71,12 +71,11 @@ class Client:
     def build_response(self, request: Request, status_code: int = 200) -> Response:
         prefix = request.headers.get('X-Forwarded-Prefix', request.scope.get('root_path', ''))
         elements = json.dumps({id: element._to_dict() for id, element in self.elements.items()})
-        socket_io_js_query_params = {**globals.socket_io_js_query_params, **{'client_id': self.id}}
+        socket_io_js_query_params = {**globals.socket_io_js_query_params, 'client_id': self.id}
         vue_html, vue_styles, vue_scripts, imports, js_imports = generate_resources(prefix, self.elements.values())
         return templates.TemplateResponse('index.html', {
             'request': request,
             'version': __version__,
-            'client_id': str(self.id),
             'elements': elements,
             'head_html': self.head_html,
             'body_html': '<style>' + '\n'.join(vue_styles) + '</style>\n' + self.body_html + '\n' + '\n'.join(vue_html),

+ 1 - 1
nicegui/globals.py

@@ -46,7 +46,7 @@ tailwind: bool
 air: Optional['Air'] = None
 socket_io_js_query_params: Dict = {}
 socket_io_js_extra_headers: Dict = {}
-# NOTE we favour websocket over polling
+# NOTE we favor websocket over polling
 socket_io_js_transports: List[Literal['websocket', 'polling']] = ['websocket', 'polling']
 
 _socket_id: Optional[str] = None

+ 1 - 1
nicegui/templates/index.html

@@ -231,7 +231,7 @@
             },
             connect_error: (err) => {
               if (err.message == 'timeout') {
-                console.log('reloading because connection time out')
+                console.log('reloading because connection timed out')
                 window.location.reload(); // see https://github.com/zauberzeug/nicegui/issues/198
               }
             },