42 lines
933 B
Python
42 lines
933 B
Python
import os
|
|
from contextlib import asynccontextmanager
|
|
|
|
from fastapi import FastAPI
|
|
from fastapi.middleware.cors import CORSMiddleware
|
|
|
|
from app.database import create_db_and_tables
|
|
from app.routers import auth, dishes, logs, products, users
|
|
|
|
|
|
@asynccontextmanager
|
|
async def lifespan(app: FastAPI):
|
|
create_db_and_tables()
|
|
yield
|
|
|
|
|
|
app = FastAPI(title="KalorienTracker API", lifespan=lifespan)
|
|
|
|
_frontend_port = os.getenv("FRONTEND_PORT", "8310")
|
|
|
|
app.add_middleware(
|
|
CORSMiddleware,
|
|
allow_origins=[
|
|
f"http://localhost:{_frontend_port}",
|
|
f"http://127.0.0.1:{_frontend_port}",
|
|
],
|
|
allow_credentials=True,
|
|
allow_methods=["*"],
|
|
allow_headers=["*"],
|
|
)
|
|
|
|
app.include_router(auth.router)
|
|
app.include_router(users.router)
|
|
app.include_router(products.router)
|
|
app.include_router(logs.router)
|
|
app.include_router(dishes.router)
|
|
|
|
|
|
@app.get("/api/health")
|
|
def health_check():
|
|
return {"status": "ok"}
|