Add function to insert app middleware (#22)

This commit is contained in:
Nikhil Rao 2022-12-01 10:55:58 -08:00 committed by GitHub
parent f0355e7f39
commit e636f0dd3e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 0 deletions

View File

@ -9,6 +9,7 @@ from .components import *
from .config import Config from .config import Config
from .constants import Env from .constants import Env
from .event import console_log, redirect, window_alert from .event import console_log, redirect, window_alert
from .middleware import Middleware
from .model import Model, session from .model import Model, session
from .state import ComputedVar as var from .state import ComputedVar as var
from .state import State from .state import State

View File

@ -162,6 +162,18 @@ class App(Base):
if out is not None: if out is not None:
return out return out
def add_middleware(self, middleware: Middleware, index: Optional[int] = None):
"""Add middleware to the app.
Args:
middleware: The middleware to add.
index: The index to add the middleware at.
"""
if index is None:
self.middleware.append(middleware)
else:
self.middleware.insert(index, middleware)
def add_page( def add_page(
self, self,
component: Union[Component, ComponentCallable], component: Union[Component, ComponentCallable],