Files
jardin/backend/app/main.py
2026-02-21 21:14:10 +01:00

34 lines
742 B
Python

import os
from contextlib import asynccontextmanager
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from app.config import CORS_ORIGINS, UPLOAD_DIR
from app.database import create_db_and_tables
@asynccontextmanager
async def lifespan(app: FastAPI):
os.makedirs(UPLOAD_DIR, exist_ok=True)
import app.models # noqa — enregistre tous les modèles avant create_all
create_db_and_tables()
from app.seed import run_seed
run_seed()
yield
app = FastAPI(title="Jardin API", lifespan=lifespan)
app.add_middleware(
CORSMiddleware,
allow_origins=CORS_ORIGINS,
allow_methods=["*"],
allow_headers=["*"],
)
@app.get("/api/health")
def health():
return {"status": "ok"}