Spaces:
Sleeping
Sleeping
File size: 968 Bytes
21ba534 |
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 |
from pathlib import Path
from fastapi import FastAPI
from starlette.middleware.cors import CORSMiddleware
from starlette.staticfiles import StaticFiles
from src.api.api import router
app = FastAPI()
# Add CORS middleware
app.add_middleware(
CORSMiddleware,
allow_origins=["*"],
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
DIR = Path(__file__).parent
static_folder = DIR / "static"
app.mount("/static", StaticFiles(directory=static_folder, html=True), name="static")
app.include_router(router)
@app.get("/{full_path:path}")
async def serve_html(full_path: str):
file_path = static_folder / full_path
if file_path.exists() and file_path.is_file():
return StaticFiles(directory=static_folder).lookup_path(file_path)
return StaticFiles(directory=static_folder).lookup_path(static_folder / "index.html")
if __name__ == "__main__":
import uvicorn
uvicorn.run(app, host="0.0.0.0", port=7860)
|