File size: 1,154 Bytes
d99646e 1f34ff7 d99646e 1f34ff7 d99646e | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 | from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from sqlalchemy import text
from app.config import settings
from app.core.database import engine
from app.models import User # noqa: F401
from app.core.database import Base
from app.routes.auth import router as auth_router
from app.routes.admin import router as admin_router
from app.routes.departments import router as departments_router
app = FastAPI(title=settings.app_name)
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(auth_router)
app.include_router(admin_router)
app.include_router(departments_router)
@app.on_event("startup")
def startup() -> None:
Base.metadata.create_all(bind=engine)
@app.get("/")
def read_root() -> dict[str, str]:
return {"status": "ok", "app": settings.app_name}
@app.get("/health/db")
def health_db() -> dict[str, str]:
with engine.connect() as connection:
connection.execute(text("SELECT 1"))
return {"status": "ok", "database": "connected"}
|