Spaces:
Runtime error
Runtime error
Download app/main.py from abdullah090809/FastAPI-Project: direct link, hf CLI and curl.
- Browser
- Download file 1.31 kB
-
https://huggingface.co/spaces/abdullah090809/FastAPI-Project/resolve/main/app/main.py
- Command line
-
hf download hf://spaces/abdullah090809/FastAPI-Project/app/main.py
-
curl -L -o main.py https://huggingface.co/spaces/abdullah090809/FastAPI-Project/resolve/main/app/main.py
1.31 kB
| from fastapi import FastAPI | |
| from fastapi.staticfiles import StaticFiles | |
| from fastapi.responses import FileResponse | |
| from app.database import Base, engine | |
| from app.routers import post, user, auth, vote | |
| from fastapi.middleware.cors import CORSMiddleware | |
| import os | |
| app = FastAPI() | |
| origins=["*"] | |
| app.add_middleware( | |
| CORSMiddleware, | |
| allow_origins=origins, | |
| allow_credentials=True, | |
| allow_methods=["*"], | |
| allow_headers=["*"], | |
| ) | |
| app.include_router(post.router) | |
| app.include_router(user.router) | |
| app.include_router(auth.router) | |
| app.include_router(vote.router) | |
| def home(): | |
| return {"message": "FastAPI Project Finished"} | |
| # Serve static files | |
| static_dir = os.path.join(os.path.dirname(__file__), "static") | |
| if os.path.exists(static_dir): | |
| app.mount("/static", StaticFiles(directory=static_dir), name="static") | |
| def serve_frontend(): | |
| return FileResponse(os.path.join(static_dir, "index.html")) | |
| def serve_spa(full_path: str): | |
| # Don't intercept API routes | |
| if full_path.startswith(("posts", "users", "login", "vote", "api")): | |
| from fastapi import HTTPException | |
| raise HTTPException(status_code=404) | |
| return FileResponse(os.path.join(static_dir, "index.html")) |