-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
27 lines (20 loc) · 827 Bytes
/
main.py
File metadata and controls
27 lines (20 loc) · 827 Bytes
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
import os
from fastapi import FastAPI, Request
from fastapi.staticfiles import StaticFiles
from fastapi.templating import Jinja2Templates
from fastapi.responses import FileResponse
UI_BUILD = "ui/build/"
UI_STATIC = "ui/build/static"
UI_PUBLIC = "ui/public/"
app = FastAPI()
templates = Jinja2Templates(directory=UI_BUILD)
app.mount("/static", StaticFiles(directory=UI_STATIC), name="ui-build-assets")
@app.get("/")
async def get_site(request: Request):
return templates.TemplateResponse("index.html", {"request": request})
@app.get("/{full_path:path}")
async def handle_spa_routing(request: Request, full_path: str):
file_path = os.path.join(UI_PUBLIC, full_path)
if os.path.exists(file_path):
return FileResponse(file_path)
return templates.TemplateResponse("index.html", {"request": request})