48 lines
1.1 KiB
Python
48 lines
1.1 KiB
Python
from contextlib import asynccontextmanager
|
|
from fastapi import FastAPI
|
|
from fastapi.middleware.cors import CORSMiddleware
|
|
from app.config import settings
|
|
from app.database import engine, Base
|
|
from app.api.v1 import router as api_v1_router
|
|
# Import all models to ensure they are registered with Base.metadata
|
|
import app.models
|
|
|
|
|
|
@asynccontextmanager
|
|
async def lifespan(app: FastAPI):
|
|
# Create DB schema tables if they do not exist
|
|
Base.metadata.create_all(bind=engine)
|
|
yield
|
|
|
|
|
|
app = FastAPI(
|
|
title=settings.PROJECT_NAME,
|
|
description="Backend API for Role-Based Hospital Admission Data Visualisation Platform",
|
|
version="1.0.0",
|
|
lifespan=lifespan,
|
|
docs_url="/docs",
|
|
redoc_url="/redoc"
|
|
)
|
|
|
|
# CORS Middleware
|
|
app.add_middleware(
|
|
CORSMiddleware,
|
|
allow_origins=settings.cors_origins,
|
|
allow_credentials=True,
|
|
allow_methods=["*"],
|
|
allow_headers=["*"],
|
|
)
|
|
|
|
# API routes
|
|
app.include_router(api_v1_router, prefix="/api")
|
|
|
|
|
|
@app.get("/health")
|
|
def health_check():
|
|
"""Service health check endpoint."""
|
|
return {
|
|
"status": "healthy",
|
|
"service": settings.PROJECT_NAME,
|
|
"environment": settings.ENV
|
|
}
|