Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from fastapi import FastAPI
|
2 |
+
from fastapi.responses import FileResponse
|
3 |
+
import os
|
4 |
+
|
5 |
+
app = FastAPI()
|
6 |
+
|
7 |
+
# Define the path to the Angular build output
|
8 |
+
frontend_dir = os.path.abspath("frontend")
|
9 |
+
|
10 |
+
# Serve the Angular index.html file for all root paths
|
11 |
+
@app.get("/{full_path:path}")
|
12 |
+
def serve_frontend(full_path: str):
|
13 |
+
file_path = os.path.join(frontend_dir, full_path)
|
14 |
+
|
15 |
+
if os.path.exists(file_path) and os.path.isfile(file_path):
|
16 |
+
return FileResponse(file_path)
|
17 |
+
else:
|
18 |
+
# Serve the index.html for any unmatched routes (to handle Angular routing)
|
19 |
+
return FileResponse(os.path.join(frontend_dir, "index.html"))
|
20 |
+
|
21 |
+
# Serve static assets (e.g., JS, CSS, images)
|
22 |
+
@app.get("/static/{full_path:path}")
|
23 |
+
def serve_static(full_path: str):
|
24 |
+
return FileResponse(os.path.join(frontend_dir, "static", full_path))
|