samwaugh commited on
Commit
63b51ff
·
1 Parent(s): 6821fcc

Space app now uses backend runner app

Browse files
Files changed (1) hide show
  1. space_app.py +12 -19
space_app.py CHANGED
@@ -1,26 +1,19 @@
 
1
  import os
2
- from flask import Flask, send_from_directory, jsonify
 
 
3
 
4
- app = Flask(__name__, static_folder="frontend", static_url_path="")
5
 
6
- @app.get("/health")
7
- def health():
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
- # Only serve files that actually exist in frontend/
19
- full_path = os.path.join(app.static_folder, path)
20
- if os.path.isfile(full_path):
21
- return send_from_directory(app.static_folder, path)
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))