Space app now uses backend runner app
Browse files- space_app.py +12 -19
space_app.py
CHANGED
|
@@ -1,26 +1,19 @@
|
|
|
|
|
| 1 |
import os
|
| 2 |
-
from
|
|
|
|
|
|
|
| 3 |
|
| 4 |
-
|
| 5 |
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
return jsonify({"status": "ok"})
|
| 9 |
-
|
| 10 |
-
# Serve the SPA
|
| 11 |
-
@app.get("/")
|
| 12 |
-
def index():
|
| 13 |
-
return send_from_directory("frontend", "index.html")
|
| 14 |
-
|
| 15 |
-
# Serve static assets under /js, /css, /images, etc.
|
| 16 |
@app.route("/<path:path>")
|
| 17 |
-
def static_proxy(path):
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
# Fallback to SPA (for hash/relative routes if any)
|
| 23 |
-
return send_from_directory("frontend", "index.html")
|
| 24 |
|
| 25 |
if __name__ == "__main__":
|
| 26 |
port = int(os.environ.get("PORT", 7860))
|
|
|
|
| 1 |
+
# space_app.py
|
| 2 |
import os
|
| 3 |
+
from pathlib import Path
|
| 4 |
+
from flask import send_from_directory
|
| 5 |
+
from backend.runner.app import app # <-- reuse the backend Flask app
|
| 6 |
|
| 7 |
+
FRONTEND_DIR = (Path(__file__).parent / "frontend").resolve()
|
| 8 |
|
| 9 |
+
# Serve SPA + static from the same app/host as the API
|
| 10 |
+
@app.route("/", defaults={"path": ""})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
@app.route("/<path:path>")
|
| 12 |
+
def static_proxy(path: str):
|
| 13 |
+
target = FRONTEND_DIR / path
|
| 14 |
+
if path and target.exists() and target.is_file():
|
| 15 |
+
return send_from_directory(str(FRONTEND_DIR), path)
|
| 16 |
+
return send_from_directory(str(FRONTEND_DIR), "index.html")
|
|
|
|
|
|
|
| 17 |
|
| 18 |
if __name__ == "__main__":
|
| 19 |
port = int(os.environ.get("PORT", 7860))
|