dhammawatthumpra commited on
Commit
faab8c8
Β·
1 Parent(s): 60c1bf8

fix: serve all root-level static files (icons, favicon.svg, apple-touch-icons)

Browse files
Files changed (1) hide show
  1. 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
- @app.get("/favicon.ico", include_in_schema=False)
107
- @app.get("/manifest.json", include_in_schema=False)
108
- @app.get("/robots.txt", include_in_schema=False)
109
- async def serve_root_static(request: Request):
110
- filename = request.url.path.lstrip("/")
111
- file = static_path / filename
112
- if file.exists():
113
- return FileResponse(file)
114
- from fastapi import HTTPException
115
- raise HTTPException(status_code=404)
 
 
 
 
 
 
 
 
 
 
 
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.