Debian Codegraph @

docs/examples/routing/mounting_starlette_app.py

raw
1 from typing import TYPE_CHECKING
2
3 from starlette.applications import Starlette
4 from starlette.responses import JSONResponse
5 from starlette.routing import Route
6
7 from litestar import Litestar, asgi
8
9 if TYPE_CHECKING:
10 from starlette.requests import Request
11
12
13 async def index(request: "Request") -> JSONResponse:
14 """A generic starlette handler."""
15 return JSONResponse({"forwarded_path": request.url.path})
16
17
18 starlette_app = asgi(path="/some/sub-path", is_mount=True, copy_scope=True)(
19 Starlette(
20 routes=[
21 Route("/", index),
22 Route("/abc/", index),
23 Route("/123/another/sub-path/", index),
24 ],
25 )
26 )
27
28
29 app = Litestar(route_handlers=[starlette_app])