Mount FastAPI backend routes at router head for direct REST API access
Browse files
app.py
CHANGED
|
@@ -60,11 +60,12 @@ 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 |
|
| 69 |
if __name__ == "__main__":
|
| 70 |
demo.launch()
|
|
|
|
| 60 |
* **Drone VRA:** Autonomous Spot-Spraying Lawnmower Grid Generator
|
| 61 |
""")
|
| 62 |
|
| 63 |
+
# Attach all FastAPI backend routes to the FRONT of Gradio's router
|
| 64 |
+
# This ensures REST API endpoints (/api/v1/..., /health, /docs) take precedence
|
| 65 |
+
# over Gradio's catch-all SPA route, while the root '/' serves the Gradio UI.
|
| 66 |
+
backend_routes = [r for r in backend_app.routes]
|
| 67 |
+
gradio_routes = [r for r in demo.app.router.routes if getattr(r, 'path', '') not in {getattr(br, 'path', '') for br in backend_routes}]
|
| 68 |
+
demo.app.router.routes = backend_routes + gradio_routes
|
| 69 |
|
| 70 |
if __name__ == "__main__":
|
| 71 |
demo.launch()
|