Skip to content

Commit

Permalink
Merge pull request #5 from peterschutt/reset-paths-before-send
Browse files Browse the repository at this point in the history
reset-paths-before-send
  • Loading branch information
peterschutt authored Apr 28, 2024
2 parents 43b07b0 + 8702519 commit af90085
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/sqladmin_litestar_plugin/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,13 @@ class PathFixMiddleware:
SQLAdmin uses `Mount` to register the admin app, and the admin app contains `Route`s.
Litestar forwards all paths without a leading forward slash, and with a trailing one.
This middleware fixes the path in the scope to ensure that the path is set correctly for the
admin app, depending on whether the request forwarded to the admin app is the base url of the
admin app or not.
"""

def __init__(self, app: st_types.ASGIApp, *, base_url: str) -> None:
self.app = app
self.base_url = base_url.rstrip("/")
Expand All @@ -133,8 +136,8 @@ def reset_paths() -> None:
scope["raw_path"] = orig_raw

async def send_wrapper(message: Any) -> None:
await send(message)
reset_paths()
await send(message)

try:
await self.app(scope, receive, send_wrapper)
Expand Down

0 comments on commit af90085

Please sign in to comment.