mirror of
https://github.com/CJackHwang/ds2api.git
synced 2026-05-04 16:35:27 +08:00
Build webui during Vercel deployment
This commit is contained in:
@@ -290,14 +290,19 @@ async def webui(request: Request, path: str = ""):
|
||||
if path and "." in path:
|
||||
file_path = os.path.join(STATIC_ADMIN_DIR, path)
|
||||
if os.path.isfile(file_path):
|
||||
return FileResponse(file_path)
|
||||
cache_control = "public, max-age=31536000, immutable"
|
||||
if path.startswith("assets/"):
|
||||
headers = {"Cache-Control": cache_control}
|
||||
else:
|
||||
headers = {"Cache-Control": "no-store, must-revalidate"}
|
||||
return FileResponse(file_path, headers=headers)
|
||||
return HTMLResponse(content="Not Found", status_code=404)
|
||||
|
||||
# 否则返回 index.html(SPA 路由)
|
||||
index_path = os.path.join(STATIC_ADMIN_DIR, "index.html")
|
||||
if os.path.isfile(index_path):
|
||||
return FileResponse(index_path)
|
||||
headers = {"Cache-Control": "no-store, must-revalidate"}
|
||||
return FileResponse(index_path, headers=headers)
|
||||
|
||||
return HTMLResponse(content="index.html not found", status_code=404)
|
||||
|
||||
|
||||
|
||||
23
vercel.json
23
vercel.json
@@ -6,10 +6,31 @@
|
||||
"use": "@vercel/python"
|
||||
}
|
||||
],
|
||||
"buildCommand": "bash scripts/build-webui.sh",
|
||||
"routes": [
|
||||
{
|
||||
"src": "/(.*)",
|
||||
"dest": "app.py"
|
||||
}
|
||||
],
|
||||
"headers": [
|
||||
{
|
||||
"source": "/admin/assets/(.*)",
|
||||
"headers": [
|
||||
{
|
||||
"key": "Cache-Control",
|
||||
"value": "public, max-age=31536000, immutable"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"source": "/admin/(.*)",
|
||||
"headers": [
|
||||
{
|
||||
"key": "Cache-Control",
|
||||
"value": "no-store, must-revalidate"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user