Skip to content

Commit

Permalink
HH-228148 make default router more visible; update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
sintell committed Aug 29, 2024
1 parent 526a4cc commit 5bfffd1
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
7 changes: 6 additions & 1 deletion docs/routing.md
Original file line number Diff line number Diff line change
@@ -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:

Expand Down
4 changes: 2 additions & 2 deletions frontik/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion frontik/routing.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 5bfffd1

Please sign in to comment.