Spaces:
Sleeping
Sleeping
alexchilton Copilot commited on
Commit ·
6b65db9
1
Parent(s): 6242ddb
Fix SPA routing guard and set demo env
Browse files- Prevent catch-all SPA route from intercepting API/docs paths
- Set APP_ENV=demo to keep docs accessible for demo
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- Dockerfile +1 -1
- backend/app/main.py +3 -0
Dockerfile
CHANGED
|
@@ -37,7 +37,7 @@ RUN mkdir -p uploads model_cache data && \
|
|
| 37 |
chown -R appuser:appuser /app
|
| 38 |
|
| 39 |
ENV PORT=7860
|
| 40 |
-
ENV APP_ENV=
|
| 41 |
ENV LOG_LEVEL=INFO
|
| 42 |
ENV TRANSFORMERS_CACHE=/app/model_cache
|
| 43 |
ENV SENTENCE_TRANSFORMERS_HOME=/app/model_cache
|
|
|
|
| 37 |
chown -R appuser:appuser /app
|
| 38 |
|
| 39 |
ENV PORT=7860
|
| 40 |
+
ENV APP_ENV=demo
|
| 41 |
ENV LOG_LEVEL=INFO
|
| 42 |
ENV TRANSFORMERS_CACHE=/app/model_cache
|
| 43 |
ENV SENTENCE_TRANSFORMERS_HOME=/app/model_cache
|
backend/app/main.py
CHANGED
|
@@ -97,6 +97,9 @@ if STATIC_DIR.is_dir():
|
|
| 97 |
@app.get("/{full_path:path}")
|
| 98 |
async def serve_spa(full_path: str):
|
| 99 |
"""Serve the SPA index.html for all non-API routes."""
|
|
|
|
|
|
|
|
|
|
| 100 |
file_path = STATIC_DIR / full_path
|
| 101 |
if file_path.is_file():
|
| 102 |
return FileResponse(str(file_path))
|
|
|
|
| 97 |
@app.get("/{full_path:path}")
|
| 98 |
async def serve_spa(full_path: str):
|
| 99 |
"""Serve the SPA index.html for all non-API routes."""
|
| 100 |
+
# Don't intercept API, docs, health, or metrics paths
|
| 101 |
+
if full_path.startswith(("api/", "docs", "redoc", "openapi.json", "health", "metrics")):
|
| 102 |
+
return JSONResponse(status_code=404, content={"detail": "Not found"})
|
| 103 |
file_path = STATIC_DIR / full_path
|
| 104 |
if file_path.is_file():
|
| 105 |
return FileResponse(str(file_path))
|