diff --git a/mcpgateway/main.py b/mcpgateway/main.py index 710c078a1..ef1f5e1b7 100644 --- a/mcpgateway/main.py +++ b/mcpgateway/main.py @@ -5261,25 +5261,21 @@ async def cleanup_import_statuses(max_age_hours: int = 24, user=Depends(get_curr # Redirect root path to admin UI @app.get("/") - async def root_redirect(request: Request): + async def root_redirect(): """ - Redirects the root path ("/") to "/admin". + Redirects the root path ("/") to "/admin/". Logs a debug message before redirecting. - Args: - request (Request): The incoming HTTP request (used only to build the - target URL via :pymeth:`starlette.requests.Request.url_for`). - Returns: - RedirectResponse: Redirects to /admin. + RedirectResponse: Redirects to /admin/. Raises: HTTPException: If there is an error during redirection. """ - logger.debug("Redirecting root path to /admin") - root_path = request.scope.get("root_path", "") - return RedirectResponse(f"{root_path}/admin", status_code=303) + logger.debug("Redirecting root path to /admin/") + root_path = settings.app_root_path + return RedirectResponse(f"{root_path}/admin/", status_code=303) # return RedirectResponse(request.url_for("admin_home")) else: diff --git a/tests/unit/mcpgateway/test_main.py b/tests/unit/mcpgateway/test_main.py index fabf401bc..675d1e122 100644 --- a/tests/unit/mcpgateway/test_main.py +++ b/tests/unit/mcpgateway/test_main.py @@ -328,9 +328,9 @@ def test_root_redirect(self, test_client): # Check if UI is enabled if settings.mcpgateway_ui_enabled: - # When UI is enabled, should redirect to admin + # When UI is enabled, should redirect to admin with trailing slash assert response.status_code == 303 - assert response.headers["location"] == "/admin" + assert response.headers["location"] == f"{settings.app_root_path}/admin/" else: # When UI is disabled, should return API info assert response.status_code == 200 diff --git a/tests/unit/mcpgateway/test_main_extended.py b/tests/unit/mcpgateway/test_main_extended.py index 2079b692d..001b4801f 100644 --- a/tests/unit/mcpgateway/test_main_extended.py +++ b/tests/unit/mcpgateway/test_main_extended.py @@ -18,6 +18,7 @@ import pytest # First-Party +from mcpgateway.config import settings from mcpgateway.main import app @@ -186,9 +187,9 @@ def test_root_endpoint_conditional_behavior(self): client = TestClient(app) response = client.get("/", follow_redirects=False) - # Should redirect to /admin when UI is enabled + # Should redirect to /admin/ when UI is enabled if response.status_code == 303: - assert response.headers.get("location") == "/admin" + assert response.headers.get("location") == f"{settings.app_root_path}/admin/" else: # Fallback behavior assert response.status_code == 200