Skip to content

Commit 8f5697c

Browse files
committed
add python requirements for frontendserver
1 parent 10cd605 commit 8f5697c

File tree

4 files changed

+89
-5
lines changed

4 files changed

+89
-5
lines changed

src/frontend_react/.env.example

Lines changed: 0 additions & 5 deletions
This file was deleted.

src/frontend_react/.env.sample

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# This is a sample .env file for the frontend application.
2+
3+
API_URL=http://localhost:8000
4+
ENABLE_AUTH=false
5+
# VITE_APP_MSAL_AUTH_CLIENTID=""
6+
# VITE_APP_MSAL_AUTH_AUTHORITY=""
7+
# VITE_APP_MSAL_REDIRECT_URL="/"
8+
# VITE_APP_MSAL_POST_REDIRECT_URL="/"
9+
# REACT_APP_MSAL_AUTH_CLIENTID=""
10+
# REACT_APP_MSAL_AUTH_AUTHORITY=""
11+
# REACT_APP_MSAL_REDIRECT_URL="/"
12+
# REACT_APP_MSAL_POST_REDIRECT_URL="/"
13+
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
import os
2+
3+
import uvicorn
4+
from dotenv import load_dotenv
5+
from fastapi import FastAPI
6+
from fastapi.middleware.cors import CORSMiddleware
7+
from fastapi.responses import FileResponse, HTMLResponse
8+
from fastapi.staticfiles import StaticFiles
9+
10+
# Load environment variables from .env file
11+
load_dotenv()
12+
13+
app = FastAPI()
14+
15+
app.add_middleware(
16+
CORSMiddleware,
17+
allow_origins=["*"],
18+
allow_methods=["*"],
19+
allow_headers=["*"],
20+
)
21+
22+
# Build paths
23+
BUILD_DIR = os.path.join(os.path.dirname(__file__), "dist")
24+
INDEX_HTML = os.path.join(BUILD_DIR, "index.html")
25+
26+
# Serve static files from build directory
27+
app.mount(
28+
"/assets", StaticFiles(directory=os.path.join(BUILD_DIR, "assets")), name="assets"
29+
)
30+
31+
32+
@app.get("/")
33+
async def serve_index():
34+
return FileResponse(INDEX_HTML)
35+
36+
37+
@app.get("/config")
38+
async def get_config():
39+
config = {
40+
"API_URL": os.getenv("API_URL", "API_URL not set"),
41+
"REACT_APP_MSAL_AUTH_CLIENTID": os.getenv(
42+
"REACT_APP_MSAL_AUTH_CLIENTID", "Client ID not set"
43+
),
44+
"REACT_APP_MSAL_AUTH_AUTHORITY": os.getenv(
45+
"REACT_APP_MSAL_AUTH_AUTHORITY", "Authority not set"
46+
),
47+
"REACT_APP_MSAL_REDIRECT_URL": os.getenv(
48+
"REACT_APP_MSAL_REDIRECT_URL", "Redirect URL not set"
49+
),
50+
"REACT_APP_MSAL_POST_REDIRECT_URL": os.getenv(
51+
"REACT_APP_MSAL_POST_REDIRECT_URL", "Post Redirect URL not set"
52+
),
53+
"ENABLE_AUTH": os.getenv("ENABLE_AUTH", "false"),
54+
}
55+
return config
56+
57+
58+
@app.get("/{full_path:path}")
59+
async def serve_app(full_path: str):
60+
# First check if file exists in build directory
61+
file_path = os.path.join(BUILD_DIR, full_path)
62+
if os.path.exists(file_path):
63+
return FileResponse(file_path)
64+
# Otherwise serve index.html for client-side routing
65+
return FileResponse(INDEX_HTML)
66+
67+
68+
if __name__ == "__main__":
69+
uvicorn.run(app, host="127.0.0.1", port=3000)
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
fastapi
2+
uvicorn[standard]
3+
# uvicorn removed and added above to allow websocket support
4+
jinja2
5+
azure-identity
6+
python-dotenv
7+
python-multipart

0 commit comments

Comments
 (0)