diff --git a/docs/routing.md b/docs/routing.md index 78ec89c09..71f646443 100644 --- a/docs/routing.md +++ b/docs/routing.md @@ -1,7 +1,12 @@ ## Routing in Frontik applications On application start, frontik import all modules from {app_module}.pages so that any controller should be located there. -We use fastapi routing, read [these docs](https://fastapi.tiangolo.com/reference/apirouter/?h=apirouter) for details. A small important difference - you must inherit `frontik.routing.FastAPIRouter` instead `fastapi.APIRouter`. And use `from frontik.routing import router`, if you need default router. +We use fastapi routing, read [these docs](https://fastapi.tiangolo.com/reference/apirouter/?h=apirouter) for details. + +> [!IMPORTANT] +> Never use `fastapi.APIRouter` router directly, instead you should import wrapped alternative from [`frontik.routing.FastAPIRouter`](https://github.com/hhru/frontik/blob/526a4cc22d151694fa48439f884dd03a6ca2329f/frontik/routing.py#L110) +> +> In any case you need the default FastAPI router — use `from frontik.routing import default_fastapi_router` example: diff --git a/frontik/app.py b/frontik/app.py index f3a3500db..119cf8793 100644 --- a/frontik/app.py +++ b/frontik/app.py @@ -30,7 +30,7 @@ method_not_allowed_router, not_found_router, regex_router, - router, + default_fastapi_router, routers, ) from frontik.service_discovery import MasterServiceDiscovery, ServiceDiscovery, WorkerServiceDiscovery @@ -42,7 +42,7 @@ class FrontikAsgiApp(FastAPI): def __init__(self) -> None: super().__init__() - self.router = router + self.router = default_fastapi_router self.http_client_factory = None if options.openapi_enabled: diff --git a/frontik/routing.py b/frontik/routing.py index c4f59ca02..f6669147e 100644 --- a/frontik/routing.py +++ b/frontik/routing.py @@ -167,7 +167,7 @@ def import_all_pages(app_module: str) -> None: plain_router = FrontikRouter() -router = FastAPIRouter(include_in_app=False) +default_fastapi_router = FastAPIRouter(include_in_app=False) not_found_router = FrontikRouter() method_not_allowed_router = FrontikRouter() regex_router = FrontikRegexRouter()