Browse Source

ability to set storage_secret for run_with

awfulness 1 year ago
parent
commit
1c0eab7886
1 changed files with 6 additions and 0 deletions
  1. 6 0
      nicegui/run_with.py

+ 6 - 0
nicegui/run_with.py

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