45 lines
1.2 KiB
Python
45 lines
1.2 KiB
Python
import logging
|
|
import traceback
|
|
from fastapi import FastAPI, Request
|
|
from fastapi.middleware.cors import CORSMiddleware
|
|
from fastapi.responses import JSONResponse
|
|
from .core.db import engine
|
|
from .models import Base
|
|
from .routers import health
|
|
|
|
# Logging setup
|
|
logging.basicConfig(
|
|
format="%(asctime)s | %(levelname)s | %(name)s | %(message)s",
|
|
level=logging.INFO,
|
|
)
|
|
logger = logging.getLogger("poona_ams")
|
|
|
|
app = FastAPI(title="Poona Hospital AMS", version="0.1.0", docs_url="/docs")
|
|
|
|
app.add_middleware(
|
|
CORSMiddleware,
|
|
allow_origins=["http://localhost:5173", "http://127.0.0.1:5173"],
|
|
allow_credentials=True,
|
|
allow_methods=["*"],
|
|
allow_headers=["*"],
|
|
)
|
|
|
|
|
|
@app.exception_handler(Exception)
|
|
async def global_exception_handler(request: Request, exc: Exception):
|
|
logger.error(f"Unhandled exception: {traceback.format_exc()}")
|
|
return JSONResponse(
|
|
status_code=500,
|
|
content={"detail": "An internal error occurred.", "code": "INTERNAL_ERROR"},
|
|
)
|
|
|
|
|
|
app.include_router(health.router, prefix="/api")
|
|
|
|
|
|
@app.on_event("startup")
|
|
def startup():
|
|
Base.metadata.create_all(bind=engine)
|
|
logger.info("Database tables created/verified.")
|
|
logger.info("Poona Hospital AMS started.")
|