49 lines
1.2 KiB
Python
49 lines
1.2 KiB
Python
from __future__ import annotations
|
|
|
|
from os import getenv
|
|
|
|
from fastapi import FastAPI
|
|
from fastapi.middleware.cors import CORSMiddleware
|
|
from dotenv import load_dotenv
|
|
|
|
from backend.app.api import routes_config, routes_debug, routes_products, routes_scrape
|
|
from backend.app.core.logging import logger
|
|
from backend.app.core.scheduler import start_scheduler
|
|
from backend.app.db.database import Base, engine
|
|
|
|
load_dotenv()
|
|
|
|
app = FastAPI(title="suivi_produit")
|
|
|
|
# CORS pour le frontend
|
|
app.add_middleware(
|
|
CORSMiddleware,
|
|
allow_origins=["http://localhost:5173", "http://127.0.0.1:5173"],
|
|
allow_credentials=True,
|
|
allow_methods=["*"],
|
|
allow_headers=["*"],
|
|
)
|
|
|
|
app.include_router(routes_products.router)
|
|
app.include_router(routes_scrape.router)
|
|
app.include_router(routes_config.router)
|
|
app.include_router(routes_debug.router)
|
|
|
|
|
|
@app.on_event("startup")
|
|
def on_startup() -> None:
|
|
Base.metadata.create_all(bind=engine)
|
|
# démarrer le scheduler APScheduler en chargeant la config
|
|
start_scheduler()
|
|
logger.info("Application démarrée (%s)", getenv("APP_ENV", "development"))
|
|
|
|
|
|
@app.get("/health")
|
|
def health() -> dict[str, str]:
|
|
# endpoint de santé minimal
|
|
return {"statut": "ok"}
|
|
|
|
|
|
def main() -> FastAPI:
|
|
return app
|