Besjon Cifliku commited on
Commit ·
bf9e9a4
1
Parent(s): db764ae
fix: build frontend serve files fails 404
Browse files- frontend/vite.config.ts +1 -0
- server.py +15 -12
frontend/vite.config.ts
CHANGED
|
@@ -3,6 +3,7 @@ import react from "@vitejs/plugin-react";
|
|
| 3 |
|
| 4 |
export default defineConfig({
|
| 5 |
plugins: [react()],
|
|
|
|
| 6 |
server: {
|
| 7 |
proxy: {
|
| 8 |
"/api/logs/stream": {
|
|
|
|
| 3 |
|
| 4 |
export default defineConfig({
|
| 5 |
plugins: [react()],
|
| 6 |
+
base: "./",
|
| 7 |
server: {
|
| 8 |
proxy: {
|
| 9 |
"/api/logs/stream": {
|
server.py
CHANGED
|
@@ -768,18 +768,21 @@ def _serialize_analysis(analysis):
|
|
| 768 |
_FRONTEND_DIR = BASE_DIR / "frontend" / "dist"
|
| 769 |
|
| 770 |
if _FRONTEND_DIR.is_dir():
|
| 771 |
-
|
| 772 |
-
|
| 773 |
-
|
| 774 |
-
|
| 775 |
-
|
| 776 |
-
|
| 777 |
-
|
| 778 |
-
|
| 779 |
-
|
| 780 |
-
|
| 781 |
-
|
| 782 |
-
|
|
|
|
|
|
|
|
|
|
| 783 |
|
| 784 |
|
| 785 |
if __name__ == "__main__":
|
|
|
|
| 768 |
_FRONTEND_DIR = BASE_DIR / "frontend" / "dist"
|
| 769 |
|
| 770 |
if _FRONTEND_DIR.is_dir():
|
| 771 |
+
from starlette.exceptions import HTTPException as _StarletteHTTPException
|
| 772 |
+
|
| 773 |
+
class _SPAStaticFiles(StaticFiles):
|
| 774 |
+
"""StaticFiles with SPA fallback: unknown paths serve index.html."""
|
| 775 |
+
|
| 776 |
+
async def get_response(self, path, scope):
|
| 777 |
+
try:
|
| 778 |
+
return await super().get_response(path, scope)
|
| 779 |
+
except _StarletteHTTPException as e:
|
| 780 |
+
if e.status_code == 404:
|
| 781 |
+
return await super().get_response(".", scope)
|
| 782 |
+
raise
|
| 783 |
+
|
| 784 |
+
app.mount("/", _SPAStaticFiles(directory=str(_FRONTEND_DIR), html=True), name="frontend")
|
| 785 |
+
logger.info("Mounted frontend from %s", _FRONTEND_DIR)
|
| 786 |
|
| 787 |
|
| 788 |
if __name__ == "__main__":
|