import sys import os from pathlib import Path from fastapi import FastAPI from fastapi.staticfiles import StaticFiles # Add the parent directory of 'app' to sys.path to support 'python app/main.py' backend_dir = Path(__file__).resolve().parent.parent if str(backend_dir) not in sys.path: sys.path.insert(0, str(backend_dir)) from app.core.config import get_settings from app.core.cors import setup_cors from app.api.v1.router import router as api_router settings = get_settings() app = FastAPI(title=settings.app_name) setup_cors(app) app.include_router(api_router, prefix=settings.api_v1_prefix) # Mount storage # Assuming backend is running from backend/ directory or root. # Relative to backend/app/main.py, storage is ../../storage if run from inside app? # Usually we run uvicorn from backend/ dir. # So storage is ../storage relative to backend/ (cwd). # Or if storage is in root of workspace, and we run from backend/, it is ../storage. BASE_DIR = Path(__file__).resolve().parent.parent.parent STORAGE_DIR = BASE_DIR / "storage" STORAGE_DIR.mkdir(parents=True, exist_ok=True) app.mount(f"{settings.api_v1_prefix}/storage", StaticFiles(directory=str(STORAGE_DIR)), name="storage") @app.get("/health") def health(): return {"status": "ok"} if __name__ == "__main__": import uvicorn # When running as 'python app/main.py', the app is in the current module's 'app' variable, # but uvicorn.run("app.main:app") is better for reload support. uvicorn.run("app.main:app", host="0.0.0.0", port=8000, reload=True)