| 1 |
import json |
| 2 |
from typing import TYPE_CHECKING |
| 3 |
|
| 4 |
from litestar import Litestar, asgi |
| 5 |
from litestar.response.base import ASGIResponse |
| 6 |
|
| 7 |
if TYPE_CHECKING: |
| 8 |
from litestar.types import Receive, Scope, Send |
| 9 |
|
| 10 |
|
| 11 |
@asgi("/some/sub-path", is_mount=True, copy_scope=True) |
| 12 |
async def my_asgi_app(scope: "Scope", receive: "Receive", send: "Send") -> None: |
| 13 |
""" |
| 14 |
Args: |
| 15 |
scope: The ASGI connection scope. |
| 16 |
receive: The ASGI receive function. |
| 17 |
send: The ASGI send function. |
| 18 |
|
| 19 |
Returns: |
| 20 |
None |
| 21 |
""" |
| 22 |
body = json.dumps({"forwarded_path": scope["path"]}) |
| 23 |
response = ASGIResponse(body=body.encode("utf-8")) |
| 24 |
await response(scope, receive, send) |
| 25 |
|
| 26 |
|
| 27 |
app = Litestar(route_handlers=[my_asgi_app]) |