Create and configure the FastAPI application
()
| 55 | |
| 56 | |
| 57 | def create_app() -> FastAPI: |
| 58 | """Create and configure the FastAPI application""" |
| 59 | app = FastAPI( |
| 60 | title="DataKit", |
| 61 | description="Modern web-based data analysis tool", |
| 62 | version="0.1.0", |
| 63 | docs_url=None, # Disable automatic docs |
| 64 | redoc_url=None, # Disable automatic redoc |
| 65 | ) |
| 66 | |
| 67 | static_path = get_static_path() |
| 68 | |
| 69 | # Mount static files |
| 70 | app.mount("/static", StaticFiles(directory=static_path), name="static") |
| 71 | |
| 72 | @app.get("/") |
| 73 | async def read_root(): |
| 74 | """Serve the main index.html file""" |
| 75 | index_file = static_path / "index.html" |
| 76 | if index_file.exists(): |
| 77 | return FileResponse(index_file) |
| 78 | else: |
| 79 | return {"error": "DataKit static files not found"} |
| 80 | |
| 81 | @app.get("/{full_path:path}") |
| 82 | async def catch_all(request: Request, full_path: str): |
| 83 | """Handle client-side routing by serving index.html for all routes""" |
| 84 | # Check if it's a request for a static file |
| 85 | file_path = static_path / full_path |
| 86 | |
| 87 | # If file exists, serve it |
| 88 | if file_path.is_file(): |
| 89 | return FileResponse(file_path) |
| 90 | |
| 91 | # For everything else (SPA routes), serve index.html |
| 92 | index_file = static_path / "index.html" |
| 93 | if index_file.exists(): |
| 94 | return FileResponse(index_file) |
| 95 | else: |
| 96 | return {"error": "DataKit static files not found"} |
| 97 | |
| 98 | return app |
| 99 | |
| 100 | |
| 101 | def run_server( |
no test coverage detected