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
This commit is contained in:
1 parent
d4ae37fef8
commit
b1bb564957
5 files changed
+35
-6
No files matched your search
@@ -101,6 +101,11 @@ if os.path.isdir(ASSETS_DIR):
|
|||||||
|
|
||||||
|
|
||||||
@app.get("/birthday", include_in_schema=False)
|
@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)
|
@app.get("/birthday/{full_path:path}", include_in_schema=False)
|
||||||
async def spa_catch_all(full_path: str = ""):
|
async def spa_catch_all(full_path: str = ""):
|
||||||
if full_path:
|
if full_path:
|
||||||
|
|||||||
@@ -1,12 +1,13 @@
|
|||||||
import pytest
|
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 fastapi.testclient import TestClient
|
||||||
from sqlalchemy import create_engine
|
from sqlalchemy import create_engine
|
||||||
from sqlalchemy.orm import sessionmaker
|
from sqlalchemy.orm import sessionmaker
|
||||||
from sqlalchemy.pool import StaticPool
|
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
|
# Shared in-memory SQLite for testing via StaticPool
|
||||||
engine = create_engine(
|
engine = create_engine(
|
||||||
"sqlite://",
|
"sqlite://",
|
||||||
|
|||||||
@@ -101,8 +101,12 @@ def test_update_config_invalid_timezone(client):
|
|||||||
|
|
||||||
|
|
||||||
def test_spa_catch_all(client):
|
def test_spa_catch_all(client):
|
||||||
res = client.get("/birthday")
|
res = client.get("/birthday", follow_redirects=False)
|
||||||
assert res.status_code == 200
|
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")
|
res_subpath = client.get("/birthday/admin")
|
||||||
assert res_subpath.status_code == 200
|
assert res_subpath.status_code == 200
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from app.services.rsvp import normalize_phone
|
from app.services.rsvp import normalize_phone
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+19
-1
@@ -2,7 +2,22 @@ import react from "@vitejs/plugin-react";
|
|||||||
import { defineConfig } from "vite";
|
import { defineConfig } from "vite";
|
||||||
|
|
||||||
export default defineConfig({
|
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/",
|
base: "/birthday/",
|
||||||
build: {
|
build: {
|
||||||
outDir: "dist",
|
outDir: "dist",
|
||||||
@@ -13,6 +28,9 @@ export default defineConfig({
|
|||||||
"/birthday/api": {
|
"/birthday/api": {
|
||||||
target: "http://localhost:8000",
|
target: "http://localhost:8000",
|
||||||
changeOrigin: true,
|
changeOrigin: true,
|
||||||
|
headers: {
|
||||||
|
"Remote-User": "kiskaadee", // mock Authelia ForwardAuth locally
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in new issue
Block a user