diff --git a/main.py b/main.py index 73afc73..c9a8c38 100644 --- a/main.py +++ b/main.py @@ -71,7 +71,9 @@ class AuthGuardMiddleware(BaseHTTPMiddleware): """ async def dispatch(self, request: Request, call_next): - path = request.url.path # ASGI 에서 root_path 가 빠진 경로 + # ASGI scope 의 raw path 는 root_path 가 제외된 형태. + # (request.url.path 는 root_path 가 prepend 된 형태라 prefix 매칭이 어긋남) + path = request.scope.get("path", "") for prefix in _AUTH_EXEMPT_PREFIXES: if path == prefix or path.startswith(prefix): return await call_next(request) @@ -85,8 +87,8 @@ class AuthGuardMiddleware(BaseHTTPMiddleware): wants_html = "text/html" in accept or not path.startswith("/api/") if wants_html: next_path = f"{APP_ROOT_PATH}{path}" if APP_ROOT_PATH else path - if request.url.query: - next_path = f"{next_path}?{request.url.query}" + if request.scope.get("query_string"): + next_path = f"{next_path}?{request.scope['query_string'].decode('latin-1')}" sep = "&" if "?" in MAIN_LOGIN_URL else "?" target = f"{MAIN_LOGIN_URL}{sep}next={quote(next_path, safe='/')}" return RedirectResponse(url=target, status_code=302)