Browse Source

code review

Falko Schindler 2 years ago
parent
commit
a673a4abe1
5 changed files with 7 additions and 7 deletions
  1. 1 1
      main.py
  2. 1 1
      nicegui/globals.py
  3. 1 1
      nicegui/templates/index.html
  4. 3 3
      prometheus.py
  5. 1 1
      website/example.py

+ 1 - 1
main.py

@@ -27,7 +27,7 @@ ui.add_static_files('/fonts', Path(__file__).parent / 'website' / 'fonts')
 # NOTE in our global fly.io deployment we need to make sure that the websocket connects back to the same instance
 fly_instance_id = os.environ.get('FLY_ALLOC_ID', '').split('-')[0]
 if fly_instance_id:
-    nicegui_globals.socket_io_js_extra_headers = f'"fly-force-instance-id": "{fly_instance_id}"'
+    nicegui_globals.socket_io_js_extra_headers['fly-force-instance-id'] = fly_instance_id
 
 
 def add_head_html() -> None:

+ 1 - 1
nicegui/globals.py

@@ -34,7 +34,7 @@ favicon: Optional[str]
 dark: Optional[bool]
 binding_refresh_interval: float
 excludes: List[str]
-socket_io_js_extra_headers: str = ''
+socket_io_js_extra_headers: Dict = {}
 
 slot_stacks: Dict[int, List['Slot']] = {}
 clients: Dict[str, 'Client'] = {}

+ 1 - 1
nicegui/templates/index.html

@@ -89,7 +89,7 @@
         mounted() {
           const query = { client_id: "{{ client_id }}" };
           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 }};
           window.socket = io(url, { path: "{{ prefix | safe }}/ws/socket.io", query, extraHeaders });
           window.socket.on("connect", () => {
             window.socket.emit("handshake", (ok) => {

+ 3 - 3
prometheus.py

@@ -10,11 +10,11 @@ EXCLUDED_USER_AGENTS = ('bot', 'spider', 'crawler', 'monitor', 'curl',
                         'wget', 'python-requests', 'kuma', 'health check')
 
 
-def start_monitor(app: FastAPI):
+def start_monitor(app: FastAPI) -> None:
     try:
         import prometheus_client
-        visits = prometheus_client.Counter('nicegui_page_visits', 'Number of real page visits', [
-                                           'path', 'session', 'origin'])
+        visits = prometheus_client.Counter('nicegui_page_visits', 'Number of real page visits',
+                                           ['path', 'session', 'origin'])
 
         class PrometheusMiddleware(BaseHTTPMiddleware):
             async def dispatch(self, request: Request, call_next):

+ 1 - 1
website/example.py

@@ -75,7 +75,7 @@ class example:
 
 
 def _add_markdown_anchor(element: ui.markdown) -> None:
-    first_line, body = element.content.split('\n', 1)
+    first_line, _ = element.content.split('\n', 1)
     assert first_line.startswith('#### ')
     headline = first_line[5:].strip()
     headline_id = SPECIAL_CHARACTERS.sub('_', headline).lower()