Add function to insert app middleware (#22)
This commit is contained in:
parent
f0355e7f39
commit
e636f0dd3e
@ -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
|
||||||
|
@ -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],
|
||||||
|
Loading…
Reference in New Issue
Block a user