fix(backend): serve frontend at root path and move meta info to /api/meta
This commit is contained in:
@@ -47,8 +47,8 @@ app.include_router(upload.router, prefix=f"{settings.API_V1_STR}/upload", tags=[
|
||||
app.include_router(results.router, prefix=f"{settings.API_V1_STR}/results", tags=["results"])
|
||||
|
||||
|
||||
@app.get("/")
|
||||
async def root():
|
||||
@app.get("/api/meta")
|
||||
async def root_meta():
|
||||
return {
|
||||
"name": settings.APP_NAME,
|
||||
"version": settings.APP_VERSION,
|
||||
@@ -70,7 +70,17 @@ if frontend_dist_path.exists():
|
||||
@app.get("/{full_path:path}", include_in_schema=False)
|
||||
async def serve_spa(full_path: str):
|
||||
"""Serve frontend SPA - all routes go to index.html"""
|
||||
# 如果是 API 路径,且没有被前面路由捕获,返回 404
|
||||
if full_path.startswith("api/"):
|
||||
return {"detail": "Not Found"}, 404
|
||||
|
||||
# 处理根路径 ""
|
||||
if full_path == "" or full_path == "/":
|
||||
return FileResponse(frontend_dist_path / "index.html")
|
||||
|
||||
file_path = frontend_dist_path / full_path
|
||||
if file_path.exists() and file_path.is_file():
|
||||
return FileResponse(file_path)
|
||||
|
||||
# SPA 路由:返回 index.html
|
||||
return FileResponse(frontend_dist_path / "index.html")
|
||||
|
||||
Reference in New Issue
Block a user