Fix auth middleware: use insert(0) on FrozenList before app starts

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
shuki
2026-03-06 06:18:05 +02:00
parent 1800babbc2
commit ebe5645fb9

View File

@@ -120,15 +120,10 @@ def main():
public_url=public_url,
)
# Add HTTP Basic Auth middleware if API key is configured
# Add HTTP Basic Auth if API key is configured
if web_key:
_orig_make_app = server._make_app
async def _authed_make_app():
app = await _orig_make_app()
@aio_web.middleware
async def basic_auth(request, handler):
async def basic_auth_middleware(request, handler):
auth_header = request.headers.get("Authorization", "")
if auth_header.startswith("Basic "):
try:
@@ -147,7 +142,11 @@ def main():
text="Authentication required",
)
app.middlewares.insert(0, basic_auth)
_orig_make_app = server._make_app
async def _authed_make_app():
app = await _orig_make_app()
app.middlewares.insert(0, basic_auth_middleware)
return app
server._make_app = _authed_make_app