Skip to content

Commit 7fbb6e0

Browse files
Clément VALENTINclaude
andcommitted
fix(api): disable redirect_slashes to fix Vite proxy routing
When using Vite proxy with path rewrite (/api/pdl -> /pdl), FastAPI's automatic redirect from /pdl to /pdl/ broke the routing because the redirect URL (/pdl/) wasn't rewritten back to /api/pdl/ by the proxy. Changes: - Disable redirect_slashes in FastAPI app to prevent 307 redirects - Change "/" routes to "" in pdl.py and roles.py routers 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <[email protected]>
1 parent c0b51c0 commit 7fbb6e0

File tree

3 files changed

+7
-3
lines changed

3 files changed

+7
-3
lines changed

apps/api/src/main.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,10 @@ def get_servers() -> list[dict[str, str]]:
9696
"clientId": "",
9797
"usePkceWithAuthorizationCodeGrant": False,
9898
},
99+
# Disable automatic redirect from /path to /path/ to avoid 307 redirects
100+
# that break proxy routing (Vite proxy rewrites /api/path -> /path,
101+
# but redirect response /path/ doesn't get rewritten back to /api/path/)
102+
redirect_slashes=False,
99103
)
100104

101105
# Mount static files for custom Swagger CSS

apps/api/src/routers/pdl.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ class PDLUpdateOrder(BaseModel):
7070
pdl_orders: list[PDLOrderItem]
7171

7272

73-
@router.get("/", response_model=APIResponse)
73+
@router.get("", response_model=APIResponse)
7474
async def list_pdls(
7575
current_user: User = Depends(get_current_user), db: AsyncSession = Depends(get_db)
7676
) -> APIResponse:
@@ -112,7 +112,7 @@ async def list_pdls(
112112
return APIResponse(success=True, data=[pdl.model_dump() for pdl in pdl_responses])
113113

114114

115-
@router.post("/", response_model=APIResponse, status_code=status.HTTP_201_CREATED)
115+
@router.post("", response_model=APIResponse, status_code=status.HTTP_201_CREATED)
116116
async def create_pdl(
117117
pdl_data: PDLCreate = Body(
118118
...,

apps/api/src/routers/roles.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
router = APIRouter(prefix="/admin/roles", tags=["Roles"])
1515

1616

17-
@router.get("/", response_model=APIResponse)
17+
@router.get("", response_model=APIResponse)
1818
async def list_roles(
1919
current_user: User = Depends(get_current_user),
2020
db: AsyncSession = Depends(get_db)

0 commit comments

Comments
 (0)