ciyidogan commited on
Commit
2fbc024
Β·
verified Β·
1 Parent(s): 34caeeb

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -2
app.py CHANGED
@@ -47,6 +47,9 @@ if static_path.exists() and static_path.is_dir():
47
  index_path = static_path / "index.html"
48
  log(f"πŸ” index.html exists: {index_path.exists()}")
49
 
 
 
 
50
  # Serve static files (Angular assets) - only if assets directory exists
51
  assets_path = static_path / "assets"
52
  if assets_path.exists() and assets_path.is_dir():
@@ -58,10 +61,26 @@ if static_path.exists() and static_path.is_dir():
58
  index_path = static_path / "index.html"
59
  if index_path.exists():
60
  log("πŸ“„ Serving index.html")
61
- return FileResponse(str(index_path))
62
  log("⚠️ index.html not found, returning health check")
63
  return {"status": "ok", "sessions": len(session_store._sessions)} # Fallback to health check
64
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
65
  # Catch-all route for Angular routing (must be last!)
66
  @app.get("/{full_path:path}")
67
  async def serve_angular(full_path: str):
@@ -72,7 +91,7 @@ if static_path.exists() and static_path.is_dir():
72
  # Return Angular index.html for all other routes
73
  index_path = static_path / "index.html"
74
  if index_path.exists():
75
- return FileResponse(str(index_path))
76
  return {"error": "UI not found"}, 404
77
  else:
78
  log("⚠️ Static directory not found")
 
47
  index_path = static_path / "index.html"
48
  log(f"πŸ” index.html exists: {index_path.exists()}")
49
 
50
+ # Mount entire static directory
51
+ app.mount("/static", StaticFiles(directory="static"), name="static")
52
+
53
  # Serve static files (Angular assets) - only if assets directory exists
54
  assets_path = static_path / "assets"
55
  if assets_path.exists() and assets_path.is_dir():
 
61
  index_path = static_path / "index.html"
62
  if index_path.exists():
63
  log("πŸ“„ Serving index.html")
64
+ return FileResponse(str(index_path), media_type="text/html")
65
  log("⚠️ index.html not found, returning health check")
66
  return {"status": "ok", "sessions": len(session_store._sessions)} # Fallback to health check
67
 
68
+ # Serve JS files with correct MIME type
69
+ @app.get("/{filename:path}.js")
70
+ async def serve_js(filename: str):
71
+ js_path = static_path / f"{filename}.js"
72
+ if js_path.exists():
73
+ return FileResponse(str(js_path), media_type="application/javascript")
74
+ return {"error": "JS file not found"}, 404
75
+
76
+ # Serve CSS files with correct MIME type
77
+ @app.get("/{filename:path}.css")
78
+ async def serve_css(filename: str):
79
+ css_path = static_path / f"{filename}.css"
80
+ if css_path.exists():
81
+ return FileResponse(str(css_path), media_type="text/css")
82
+ return {"error": "CSS file not found"}, 404
83
+
84
  # Catch-all route for Angular routing (must be last!)
85
  @app.get("/{full_path:path}")
86
  async def serve_angular(full_path: str):
 
91
  # Return Angular index.html for all other routes
92
  index_path = static_path / "index.html"
93
  if index_path.exists():
94
+ return FileResponse(str(index_path), media_type="text/html")
95
  return {"error": "UI not found"}, 404
96
  else:
97
  log("⚠️ Static directory not found")