app.py 856 B

12345678910111213141516171819202122232425262728293031323334
  1. """FastAPI application — category tree API on port 8080."""
  2. from __future__ import annotations
  3. from fastapi import FastAPI
  4. from fastapi.middleware.cors import CORSMiddleware
  5. from api.services.category_tree import build_category_tree
  6. app = FastAPI(title="SupplyAgent API", version="0.1.0")
  7. app.add_middleware(
  8. CORSMiddleware,
  9. allow_origins=[
  10. "http://localhost:5173",
  11. "http://127.0.0.1:5173",
  12. "http://localhost:4173",
  13. "http://127.0.0.1:4173",
  14. ],
  15. allow_credentials=True,
  16. allow_methods=["*"],
  17. allow_headers=["*"],
  18. )
  19. @app.get("/health")
  20. def health() -> dict[str, str]:
  21. return {"status": "ok"}
  22. @app.get("/api/category-tree")
  23. def category_tree() -> dict:
  24. """Return the full nested global_tree_category tree in one response."""
  25. nodes = build_category_tree()
  26. return {"nodes": nodes}