""" Calories Calculator API """ import pathlib from fastapi import FastAPI from fastapi.middleware.cors import CORSMiddleware from fastapi.responses import JSONResponse from app.api.v1.api import api_router from app.core.config import settings # Create database directory if it doesn't exist DB_DIR = pathlib.Path("/app") / "storage" / "db" DB_DIR.mkdir(parents=True, exist_ok=True) app = FastAPI( title="Calories Calculator API", description="API for tracking calories and nutritional information", version="0.1.0", openapi_url="/openapi.json", ) # CORS middleware setup app.add_middleware( CORSMiddleware, allow_origins=["*"], # Allow all origins allow_credentials=False, # Must be False when using wildcard origins allow_methods=["*"], # Allows all methods allow_headers=["*"], # Allows all headers ) # Include API router app.include_router(api_router, prefix=settings.API_V1_STR) @app.get("/health", tags=["Health"]) async def health_check(): """ Health check endpoint for the API. """ return JSONResponse({"status": "healthy"}) @app.get("/openapi.json", include_in_schema=False) async def get_open_api_endpoint(): """ Return the OpenAPI schema for the API. """ return app.openapi() if __name__ == "__main__": import uvicorn uvicorn.run("main:app", host="0.0.0.0", port=8000, reload=True)