소스 검색

ability to set storage_secret for run_with

awfulness 1 년 전
부모
커밋
1c0eab7886
1개의 변경된 파일6개의 추가작업 그리고 0개의 파일을 삭제
  1. 6 0
      nicegui/run_with.py

+ 6 - 0
nicegui/run_with.py

@@ -1,10 +1,12 @@
 from typing import Optional
 from typing import Optional
 
 
 from fastapi import FastAPI
 from fastapi import FastAPI
+from starlette.middleware.sessions import SessionMiddleware
 
 
 from nicegui import globals
 from nicegui import globals
 from nicegui.language import Language
 from nicegui.language import Language
 from nicegui.nicegui import handle_shutdown, handle_startup
 from nicegui.nicegui import handle_shutdown, handle_startup
+from nicegui.storage import RequestTrackingMiddleware
 
 
 
 
 def run_with(
 def run_with(
@@ -17,6 +19,7 @@ def run_with(
     binding_refresh_interval: float = 0.1,
     binding_refresh_interval: float = 0.1,
     exclude: str = '',
     exclude: str = '',
     mount_path: str = '/',
     mount_path: str = '/',
+    storage_secret: Optional[str] = None,
 ) -> None:
 ) -> None:
     globals.ui_run_has_been_called = True
     globals.ui_run_has_been_called = True
     globals.title = title
     globals.title = title
@@ -28,6 +31,9 @@ def run_with(
     globals.excludes = [e.strip() for e in exclude.split(',')]
     globals.excludes = [e.strip() for e in exclude.split(',')]
     globals.tailwind = True
     globals.tailwind = True
 
 
+    app.add_middleware(RequestTrackingMiddleware)
+    app.add_middleware(SessionMiddleware, secret_key=storage_secret)
+
     app.on_event('startup')(lambda: handle_startup(with_welcome_message=False))
     app.on_event('startup')(lambda: handle_startup(with_welcome_message=False))
     app.on_event('shutdown')(lambda: handle_shutdown())
     app.on_event('shutdown')(lambda: handle_shutdown())