51 lines
1.3 KiB
Python
51 lines
1.3 KiB
Python
from contextlib import asynccontextmanager
|
|
from typing import AsyncIterator
|
|
|
|
from dotenv import load_dotenv
|
|
|
|
load_dotenv() # load .env before db.py reads DATABASE_URL
|
|
|
|
from fastapi import FastAPI # noqa: E402
|
|
from fastapi.middleware.cors import CORSMiddleware # noqa: E402
|
|
|
|
from db import create_db_and_tables # noqa: E402
|
|
from innercontext.api import ( # noqa: E402
|
|
ai_logs,
|
|
health,
|
|
inventory,
|
|
products,
|
|
routines,
|
|
skincare,
|
|
)
|
|
|
|
|
|
@asynccontextmanager
|
|
async def lifespan(app: FastAPI) -> AsyncIterator[None]:
|
|
create_db_and_tables()
|
|
yield
|
|
|
|
|
|
app = FastAPI(
|
|
title="innercontext API",
|
|
lifespan=lifespan,
|
|
redirect_slashes=False,
|
|
)
|
|
|
|
app.add_middleware(
|
|
CORSMiddleware, # ty: ignore[invalid-argument-type]
|
|
allow_origins=["*"],
|
|
allow_methods=["*"],
|
|
allow_headers=["*"],
|
|
)
|
|
|
|
app.include_router(products.router, prefix="/products", tags=["products"])
|
|
app.include_router(inventory.router, prefix="/inventory", tags=["inventory"])
|
|
app.include_router(health.router, prefix="/health", tags=["health"])
|
|
app.include_router(routines.router, prefix="/routines", tags=["routines"])
|
|
app.include_router(skincare.router, prefix="/skincare", tags=["skincare"])
|
|
app.include_router(ai_logs.router, prefix="/ai-logs", tags=["ai-logs"])
|
|
|
|
|
|
@app.get("/health-check")
|
|
def health_check():
|
|
return {"status": "ok"}
|