havinashpatil commited on
Commit
62c7e95
Β·
1 Parent(s): 034343c

Serve React frontend from FastAPI backend for one-click access

Browse files
Files changed (1) hide show
  1. server/app.py +16 -0
server/app.py CHANGED
@@ -10,7 +10,10 @@ from typing import Optional
10
 
11
  from fastapi import FastAPI
12
  from fastapi.middleware.cors import CORSMiddleware
 
 
13
  from pydantic import BaseModel
 
14
 
15
  from server.models import CodeArenaObservation, CodeArenaAction, TaskInfo
16
  from server.executor import run_code_with_tests
@@ -353,6 +356,19 @@ def api_memory():
353
  return {"memories": {}}
354
 
355
 
 
 
 
 
 
 
 
 
 
 
 
 
 
356
  # ── CLI entrypoint (OpenEnv / script console_scripts) ─────────────────────
357
  def main():
358
  """Run the CodeArena server via uvicorn."""
 
10
 
11
  from fastapi import FastAPI
12
  from fastapi.middleware.cors import CORSMiddleware
13
+ from fastapi.staticfiles import StaticFiles
14
+ from fastapi.responses import FileResponse
15
  from pydantic import BaseModel
16
+ import os
17
 
18
  from server.models import CodeArenaObservation, CodeArenaAction, TaskInfo
19
  from server.executor import run_code_with_tests
 
356
  return {"memories": {}}
357
 
358
 
359
+ # ── Static Frontend Serving ───────────────────────────────────────────────
360
+ dist_path = os.path.join(os.path.dirname(os.path.dirname(__file__)), "frontend", "dist")
361
+
362
+ if os.path.exists(dist_path):
363
+ app.mount("/assets", StaticFiles(directory=os.path.join(dist_path, "assets")), name="assets")
364
+
365
+ @app.get("/{full_path:path}")
366
+ def serve_frontend(full_path: str):
367
+ path_in_dist = os.path.join(dist_path, full_path)
368
+ if os.path.isfile(path_in_dist):
369
+ return FileResponse(path_in_dist)
370
+ return FileResponse(os.path.join(dist_path, "index.html"))
371
+
372
  # ── CLI entrypoint (OpenEnv / script console_scripts) ─────────────────────
373
  def main():
374
  """Run the CodeArena server via uvicorn."""