Include FastAPI backend router and reorder routes ahead of catchall
Browse files
app.py
CHANGED
|
@@ -60,12 +60,14 @@ with gr.Blocks(title="🌾 CropAI Agronomic Cloud") as demo:
|
|
| 60 |
* **Drone VRA:** Autonomous Spot-Spraying Lawnmower Grid Generator
|
| 61 |
""")
|
| 62 |
|
| 63 |
-
# Attach all FastAPI backend routes
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
demo.app.router.routes
|
|
|
|
|
|
|
| 69 |
|
| 70 |
if __name__ == "__main__":
|
| 71 |
demo.launch(ssr_mode=False)
|
|
|
|
| 60 |
* **Drone VRA:** Autonomous Spot-Spraying Lawnmower Grid Generator
|
| 61 |
""")
|
| 62 |
|
| 63 |
+
# Attach all FastAPI backend routes onto Gradio's internal FastAPI app
|
| 64 |
+
demo.app.include_router(backend_app.router)
|
| 65 |
+
|
| 66 |
+
# Move Gradio's catch-all SPA routes to the very end so that REST API endpoints
|
| 67 |
+
# (/api/v1/..., /health, /docs) take full precedence without interference.
|
| 68 |
+
non_catchall = [r for r in demo.app.router.routes if '{path:path}' not in getattr(r, 'path', '')]
|
| 69 |
+
catchall = [r for r in demo.app.router.routes if '{path:path}' in getattr(r, 'path', '')]
|
| 70 |
+
demo.app.router.routes = non_catchall + catchall
|
| 71 |
|
| 72 |
if __name__ == "__main__":
|
| 73 |
demo.launch(ssr_mode=False)
|