🩹 Fix FastAPI app initialization

This commit is contained in:
Brian Wiborg 2025-10-02 03:02:00 +02:00
parent ee4bd2760c
commit af110cec9d
No known key found for this signature in database

View file

@ -81,8 +81,8 @@ class Project:
# Attach routers from apps # Attach routers from apps
for app_name, app_def in self._apps.items(): for app_name, app_def in self._apps.items():
if app_def.router: for router in app_def.routers:
app.include_router(app_def.router) app.include_router(router)
# Startup / shutdown events # Startup / shutdown events
@app.on_event("startup") @app.on_event("startup")
@ -333,14 +333,21 @@ class App:
module: out, module: out,
} }
@property
def routers(self):
out = []
for routes_mod in self._routers:
for r in self._routers[routes_mod]:
out.append(r)
return out
@property @property
def routes(self): def routes(self):
""" """
Return an APIRouter with all loaded routes. Return an APIRouter with all loaded routes.
""" """
router = APIRouter() router = APIRouter()
for routes_mod in self._routers: for r in self.routers:
for r in self._routers[routes_mod]:
router.include_router(r) router.include_router(r)
return router.routes return router.routes