53 lines
1.4 KiB
Python
53 lines
1.4 KiB
Python
"""FastAPI application entry point."""
|
|
|
|
from contextlib import asynccontextmanager
|
|
|
|
from fastapi import FastAPI
|
|
from fastapi.middleware.cors import CORSMiddleware
|
|
|
|
from app.config import get_settings
|
|
from app.models.database import init_db
|
|
from app.api import cases, screenshots, analysis, export, settings
|
|
|
|
|
|
@asynccontextmanager
|
|
async def lifespan(app: FastAPI):
|
|
cfg = get_settings()
|
|
cfg.upload_dir.mkdir(parents=True, exist_ok=True)
|
|
await init_db()
|
|
yield
|
|
|
|
|
|
def create_app() -> FastAPI:
|
|
cfg = get_settings()
|
|
app = FastAPI(
|
|
title=cfg.app_name,
|
|
lifespan=lifespan,
|
|
)
|
|
app.add_middleware(
|
|
CORSMiddleware,
|
|
allow_origins=[
|
|
"http://localhost:3000",
|
|
"http://localhost:5173",
|
|
"http://127.0.0.1:3000",
|
|
"http://127.0.0.1:5173",
|
|
],
|
|
allow_credentials=True,
|
|
allow_methods=["*"],
|
|
allow_headers=["*"],
|
|
)
|
|
app.include_router(cases.router, prefix="/api/cases", tags=["cases"])
|
|
app.include_router(screenshots.router, prefix="/api/cases", tags=["screenshots"])
|
|
app.include_router(analysis.router, prefix="/api/cases", tags=["analysis"])
|
|
app.include_router(export.router, prefix="/api/cases", tags=["export"])
|
|
app.include_router(settings.router, prefix="/api/settings", tags=["settings"])
|
|
return app
|
|
|
|
|
|
app = create_app()
|
|
|
|
|
|
@app.get("/health")
|
|
def health():
|
|
return {"status": "ok"}
|