|
6 | 6 | from typing import List, Optional, Dict, Any |
7 | 7 | import uvicorn |
8 | 8 | import os |
| 9 | +import sys |
9 | 10 | from pathlib import Path |
10 | 11 |
|
11 | 12 | # Import our modules |
|
54 | 55 | except ImportError: |
55 | 56 | from paths import get_paths |
56 | 57 |
|
57 | | -# Mount static files for audio cache and frontend |
| 58 | +# Mount static files for audio cache |
58 | 59 | paths = get_paths() |
59 | 60 | app.mount("/audio_cache", StaticFiles(directory=str(paths.audio_cache)), name="audio_cache") |
60 | 61 |
|
61 | | -# Mount frontend static files |
62 | | -frontend_path = paths.base_path / "frontend" / "dist" |
63 | | -if frontend_path.exists(): |
64 | | - app.mount("/", StaticFiles(directory=str(frontend_path), html=True), name="frontend") |
65 | | -else: |
66 | | - # Fallback for development when running from source |
67 | | - dev_frontend_path = Path(__file__).parent.parent / "frontend" / "dist" |
68 | | - if dev_frontend_path.exists(): |
69 | | - app.mount("/", StaticFiles(directory=str(dev_frontend_path), html=True), name="frontend") |
70 | | - |
71 | 62 | # API info endpoint (moved from root to avoid conflict with frontend) |
72 | 63 | @app.get("/api/info") |
73 | 64 | async def api_info(): |
@@ -288,6 +279,25 @@ async def get_available_voices(omni_model: str): |
288 | 279 | except Exception as e: |
289 | 280 | raise HTTPException(status_code=500, detail=f"Error getting voices: {str(e)}") |
290 | 281 |
|
| 282 | +# Mount frontend static files (moved after API endpoints to avoid conflicts) |
| 283 | +if getattr(sys, 'frozen', False): |
| 284 | + # Running as PyInstaller bundle - frontend files are in the bundled directory |
| 285 | + bundled_frontend_path = Path(sys._MEIPASS) / "frontend" / "dist" |
| 286 | + if bundled_frontend_path.exists(): |
| 287 | + app.mount("/", StaticFiles(directory=str(bundled_frontend_path), html=True), name="frontend") |
| 288 | + else: |
| 289 | + print(f"Warning: Frontend directory not found at {bundled_frontend_path}") |
| 290 | +else: |
| 291 | + # Development environment |
| 292 | + frontend_path = paths.base_path / "frontend" / "dist" |
| 293 | + if frontend_path.exists(): |
| 294 | + app.mount("/", StaticFiles(directory=str(frontend_path), html=True), name="frontend") |
| 295 | + else: |
| 296 | + # Fallback for development when running from source |
| 297 | + dev_frontend_path = Path(__file__).parent.parent / "frontend" / "dist" |
| 298 | + if dev_frontend_path.exists(): |
| 299 | + app.mount("/", StaticFiles(directory=str(dev_frontend_path), html=True), name="frontend") |
| 300 | + |
291 | 301 | # Error handler |
292 | 302 | @app.exception_handler(Exception) |
293 | 303 | async def general_exception_handler(request, exc): |
|
0 commit comments