diff --git a/pyproject.toml b/pyproject.toml index 211b709..8415c9c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -38,6 +38,7 @@ addopts = "--cov --cov-report term-missing --cov-fail-under=85" [tool.pytest_env] DOMAIN = "http://localhost:8010" +FRONTEND = "http://localhost:8080" RATE_LIMIT_REQUESTS = 2 RATE_LIMIT_WINDOW_SECONDS = 60 MAX_CODE_GENERATION_ATTEMPTS = 2 diff --git a/source/app.py b/source/app.py index 3a2033e..0462ede 100644 --- a/source/app.py +++ b/source/app.py @@ -4,6 +4,7 @@ from source.endpoints.decode import router as decode_router from source.endpoints.encode import router as encode_router +from source.endpoints.focal import router as focal_router from source.endpoints.management import router as management_router from source.endpoints.status import router as status_router from source.settings import settings @@ -30,6 +31,7 @@ def create_app() -> FastAPI: application.include_router(encode_router) application.include_router(management_router) application.include_router(status_router) + application.include_router(focal_router) return application diff --git a/source/endpoints/decode.py b/source/endpoints/decode.py index d4b8bf7..8fa1214 100644 --- a/source/endpoints/decode.py +++ b/source/endpoints/decode.py @@ -15,7 +15,6 @@ tags=["Encryption"], status_code=status.HTTP_308_PERMANENT_REDIRECT, responses={ - status.HTTP_308_PERMANENT_REDIRECT: {"description": "Successful redirection to the original URL."}, status.HTTP_404_NOT_FOUND: {"description": "There's no `link` assigned to this code."}, }, ) diff --git a/source/endpoints/focal.py b/source/endpoints/focal.py new file mode 100644 index 0000000..a68767b --- /dev/null +++ b/source/endpoints/focal.py @@ -0,0 +1,11 @@ +from fastapi import APIRouter, Request, status +from fastapi.responses import RedirectResponse + +from source.settings import settings + +router = APIRouter() + + +@router.get("/", summary="Redirects to frontend.", status_code=status.HTTP_308_PERMANENT_REDIRECT) +async def home(request: Request) -> RedirectResponse: # pylint: disable=unused-argument + return RedirectResponse(status_code=status.HTTP_308_PERMANENT_REDIRECT, url=settings.frontend) diff --git a/source/settings.py b/source/settings.py index 30f49ae..ad176c5 100644 --- a/source/settings.py +++ b/source/settings.py @@ -6,6 +6,7 @@ class Settings(BaseSettings): # Environment variables domain: str + frontend: str rate_limit_requests: int rate_limit_window_seconds: int database_url: str diff --git a/tests/test_endpoints/test_focal.py b/tests/test_endpoints/test_focal.py new file mode 100644 index 0000000..97700b3 --- /dev/null +++ b/tests/test_endpoints/test_focal.py @@ -0,0 +1,10 @@ +from fastapi import status +from httpx import AsyncClient + +from source.settings import settings + + +async def test_home(client: AsyncClient) -> None: + response = await client.get("/") + assert response.status_code == status.HTTP_308_PERMANENT_REDIRECT + assert response.headers["location"] == settings.frontend