Spaces:
Running
Running
Commit Β·
faab8c8
1
Parent(s): 60c1bf8
fix: serve all root-level static files (icons, favicon.svg, apple-touch-icons)
Browse files- webapp/tipitaka-api/app/main.py +22 -11
webapp/tipitaka-api/app/main.py
CHANGED
|
@@ -101,18 +101,29 @@ if settings.SERVE_STATIC:
|
|
| 101 |
logger.info(f"Mounting /assets from: {assets_dir}")
|
| 102 |
app.mount("/assets", StaticFiles(directory=str(assets_dir)), name="assets")
|
| 103 |
|
| 104 |
-
# Serve individual root-level static files (favicon, manifest, robots.txt, etc.)
|
| 105 |
# without needing a full root mount.
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 116 |
|
| 117 |
# ββ SPA catch-all: serve index.html for all non-API, non-asset routes ββ
|
| 118 |
# This is reliable because it's an explicit FastAPI route, not middleware.
|
|
|
|
| 101 |
logger.info(f"Mounting /assets from: {assets_dir}")
|
| 102 |
app.mount("/assets", StaticFiles(directory=str(assets_dir)), name="assets")
|
| 103 |
|
| 104 |
+
# Serve individual root-level static files (favicon, icons, manifest, robots.txt, etc.)
|
| 105 |
# without needing a full root mount.
|
| 106 |
+
# We explicitly list common root-level file patterns that Vite copies from public/.
|
| 107 |
+
for _static_pattern in [
|
| 108 |
+
"/favicon.ico",
|
| 109 |
+
"/favicon.svg",
|
| 110 |
+
"/manifest.json",
|
| 111 |
+
"/robots.txt",
|
| 112 |
+
"/icon-192.png",
|
| 113 |
+
"/icon-512.png",
|
| 114 |
+
"/apple-touch-icon.png",
|
| 115 |
+
"/apple-touch-icon-precomposed.png",
|
| 116 |
+
"/apple-touch-icon-120x120.png",
|
| 117 |
+
"/apple-touch-icon-120x120-precomposed.png",
|
| 118 |
+
"/icons.svg",
|
| 119 |
+
]:
|
| 120 |
+
@app.get(_static_pattern, include_in_schema=False)
|
| 121 |
+
async def serve_root_static(request: Request, _p=_static_pattern):
|
| 122 |
+
file = static_path / _p.lstrip("/")
|
| 123 |
+
if file.exists():
|
| 124 |
+
return FileResponse(file)
|
| 125 |
+
from fastapi import HTTPException
|
| 126 |
+
raise HTTPException(status_code=404)
|
| 127 |
|
| 128 |
# ββ SPA catch-all: serve index.html for all non-API, non-asset routes ββ
|
| 129 |
# This is reliable because it's an explicit FastAPI route, not middleware.
|