-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
26 lines (21 loc) · 1010 Bytes
/
main.py
File metadata and controls
26 lines (21 loc) · 1010 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
from fastapi import FastAPI
from fastapi.staticfiles import StaticFiles
from fastapi.responses import FileResponse
import os
app = FastAPI()
# Path to the Svelte build output (mounted in Docker)
STATIC_DIR = "/app/static"
# 1. Mount the assets folder (CSS/JS) generated by Svelte
# SvelteKit puts assets in _app, so we look for that.
if os.path.isdir(os.path.join(STATIC_DIR, "_app")):
app.mount("/_app", StaticFiles(directory=os.path.join(STATIC_DIR, "_app")), name="_app")
# 2. Catch-all route for SPA (Single Page Application)
# Any route not found above (like /about, /flow/123) returns index.html
@app.get("/{full_path:path}")
async def serve_spa(full_path: str):
# Check if a specific file exists (like favicon.png), serve it
file_path = os.path.join(STATIC_DIR, full_path)
if os.path.exists(file_path) and os.path.isfile(file_path):
return FileResponse(file_path)
# Otherwise return the app entry point
return FileResponse(os.path.join(STATIC_DIR, "index.html"))