From b1bb5649576ebd46b2762d661d6aa092ad6aeecb Mon Sep 17 00:00:00 2001 From: kiskaadee Date: Thu, 1 Oct 2026 01:39:29 -0500 Subject: [PATCH] fix(routing): redirect /birthday to canonical /birthday/ and mock dev auth - Redirect /birthday to /birthday/ with HTTP 307 in FastAPI and 301 in Vite dev server - Update pytest test_spa_catch_all to assert redirect behavior - Add development Remote-User header in Vite proxy for unblocked local admin testing --- backend/app/main.py | 5 +++++ backend/tests/conftest.py | 7 ++++--- backend/tests/test_config.py | 8 ++++++-- backend/tests/test_rsvp.py | 1 + frontend/vite.config.ts | 20 +++++++++++++++++++- 5 files changed, 35 insertions(+), 6 deletions(-) diff --git a/backend/app/main.py b/backend/app/main.py index b4baa51..7b2bbbd 100644 --- a/backend/app/main.py +++ b/backend/app/main.py @@ -101,6 +101,11 @@ if os.path.isdir(ASSETS_DIR): @app.get("/birthday", include_in_schema=False) +async def redirect_birthday_slash(): + return RedirectResponse(url="/birthday/", status_code=status.HTTP_307_TEMPORARY_REDIRECT) + + +@app.get("/birthday/", include_in_schema=False) @app.get("/birthday/{full_path:path}", include_in_schema=False) async def spa_catch_all(full_path: str = ""): if full_path: diff --git a/backend/tests/conftest.py b/backend/tests/conftest.py index 08dcf0d..5d3e27d 100644 --- a/backend/tests/conftest.py +++ b/backend/tests/conftest.py @@ -1,12 +1,13 @@ import pytest -from app.database import Base, get_db -from app.main import app -from app.services.config import seed_default_config from fastapi.testclient import TestClient from sqlalchemy import create_engine from sqlalchemy.orm import sessionmaker from sqlalchemy.pool import StaticPool +from app.database import Base, get_db +from app.main import app +from app.services.config import seed_default_config + # Shared in-memory SQLite for testing via StaticPool engine = create_engine( "sqlite://", diff --git a/backend/tests/test_config.py b/backend/tests/test_config.py index 2b58673..72cfae9 100644 --- a/backend/tests/test_config.py +++ b/backend/tests/test_config.py @@ -101,8 +101,12 @@ def test_update_config_invalid_timezone(client): def test_spa_catch_all(client): - res = client.get("/birthday") - assert res.status_code == 200 + res = client.get("/birthday", follow_redirects=False) + assert res.status_code == 307 + assert res.headers["location"] == "/birthday/" + + res_followed = client.get("/birthday", follow_redirects=True) + assert res_followed.status_code == 200 res_subpath = client.get("/birthday/admin") assert res_subpath.status_code == 200 diff --git a/backend/tests/test_rsvp.py b/backend/tests/test_rsvp.py index ebd37be..97f7247 100644 --- a/backend/tests/test_rsvp.py +++ b/backend/tests/test_rsvp.py @@ -1,4 +1,5 @@ import pytest + from app.services.rsvp import normalize_phone diff --git a/frontend/vite.config.ts b/frontend/vite.config.ts index 7a75285..f99c2d0 100644 --- a/frontend/vite.config.ts +++ b/frontend/vite.config.ts @@ -2,7 +2,22 @@ import react from "@vitejs/plugin-react"; import { defineConfig } from "vite"; export default defineConfig({ - plugins: [react()], + plugins: [ + react(), + { + name: "trailing-slash-redirect", + configureServer(server) { + server.middlewares.use((req, res, next) => { + if (req.url === "/birthday") { + res.writeHead(301, { Location: "/birthday/" }); + res.end(); + return; + } + next(); + }); + }, + }, + ], base: "/birthday/", build: { outDir: "dist", @@ -13,6 +28,9 @@ export default defineConfig({ "/birthday/api": { target: "http://localhost:8000", changeOrigin: true, + headers: { + "Remote-User": "kiskaadee", // mock Authelia ForwardAuth locally + }, }, }, },