-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.py
More file actions
42 lines (35 loc) · 1.35 KB
/
Copy pathserver.py
File metadata and controls
42 lines (35 loc) · 1.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
"""
Name: FlightScope Web
Course Code: ICS3U-01
Author: Sean Nie
Description: FastAPI entry point — wires up routers and serves the React build.
"""
import os
from dotenv import load_dotenv
load_dotenv()
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from fastapi.responses import FileResponse
from fastapi.staticfiles import StaticFiles
from api.opensky import router as flights_router
from api.airports import router as airports_router
from api.ai import router as ai_router
from api.user_data import router as user_router
app = FastAPI(title="FlightScope API")
app.add_middleware(
CORSMiddleware,
allow_origins=["*"],
allow_methods=["GET", "POST", "PUT", "DELETE"],
allow_headers=["*"],
)
app.include_router(flights_router)
app.include_router(airports_router)
app.include_router(ai_router)
app.include_router(user_router)
# ── Serve React build in production ───────────────────────────────────────────
_dist = os.path.join(os.path.dirname(__file__), "frontend", "dist")
if os.path.isdir(_dist):
app.mount("/assets", StaticFiles(directory=os.path.join(_dist, "assets")), name="assets")
@app.get("/{full_path:path}")
def serve_react(full_path: str):
return FileResponse(os.path.join(_dist, "index.html"))