Fix frontend compatibility with paginated API response
- Update frontend API client to extract items from paginated response - Fix SPA routing to serve index.html for /project/* paths on refresh 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -57,11 +57,12 @@ if os.path.exists(static_dir):
|
|||||||
# Catch-all for SPA routing (must be last)
|
# Catch-all for SPA routing (must be last)
|
||||||
@app.get("/{full_path:path}")
|
@app.get("/{full_path:path}")
|
||||||
async def serve_spa_routes(full_path: str):
|
async def serve_spa_routes(full_path: str):
|
||||||
# Don't catch API routes
|
# Don't catch API routes or health endpoint
|
||||||
if full_path.startswith("api/") or full_path.startswith("health") or full_path.startswith("project/"):
|
if full_path.startswith("api/") or full_path.startswith("health"):
|
||||||
from fastapi import HTTPException
|
from fastapi import HTTPException
|
||||||
raise HTTPException(status_code=404, detail="Not found")
|
raise HTTPException(status_code=404, detail="Not found")
|
||||||
|
|
||||||
|
# Serve SPA for all other routes (including /project/*)
|
||||||
index_path = os.path.join(static_dir, "index.html")
|
index_path = os.path.join(static_dir, "index.html")
|
||||||
if os.path.exists(index_path):
|
if os.path.exists(index_path):
|
||||||
return FileResponse(index_path)
|
return FileResponse(index_path)
|
||||||
|
|||||||
@@ -10,10 +10,22 @@ async function handleResponse<T>(response: Response): Promise<T> {
|
|||||||
return response.json();
|
return response.json();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Paginated response type
|
||||||
|
interface PaginatedResponse<T> {
|
||||||
|
items: T[];
|
||||||
|
pagination: {
|
||||||
|
page: number;
|
||||||
|
limit: number;
|
||||||
|
total: number;
|
||||||
|
total_pages: number;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
// Project API
|
// Project API
|
||||||
export async function listProjects(): Promise<Project[]> {
|
export async function listProjects(): Promise<Project[]> {
|
||||||
const response = await fetch(`${API_BASE}/projects`);
|
const response = await fetch(`${API_BASE}/projects`);
|
||||||
return handleResponse<Project[]>(response);
|
const data = await handleResponse<PaginatedResponse<Project>>(response);
|
||||||
|
return data.items;
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function createProject(data: { name: string; description?: string; is_public?: boolean }): Promise<Project> {
|
export async function createProject(data: { name: string; description?: string; is_public?: boolean }): Promise<Project> {
|
||||||
|
|||||||
Reference in New Issue
Block a user