Added Commands Management
This commit is contained in:
19
src/myfasthtml/core/utils.py
Normal file
19
src/myfasthtml/core/utils.py
Normal file
@@ -0,0 +1,19 @@
|
||||
from starlette.routing import Mount
|
||||
|
||||
|
||||
def mount_if_not_exists(app, path: str, sub_app):
|
||||
"""
|
||||
Mounts a sub-application only if no Mount object already exists
|
||||
at the specified path in the main application's router.
|
||||
"""
|
||||
is_mounted = False
|
||||
|
||||
for route in app.router.routes:
|
||||
|
||||
if isinstance(route, Mount):
|
||||
if route.path == path:
|
||||
is_mounted = True
|
||||
break
|
||||
|
||||
if not is_mounted:
|
||||
app.mount(path, app=sub_app)
|
||||
Reference in New Issue
Block a user