76 lines
2.0 KiB
Python
76 lines
2.0 KiB
Python
|
|
"""
|
||
|
|
FastAPI application entry point with CORS configuration
|
||
|
|
"""
|
||
|
|
import logging
|
||
|
|
import os
|
||
|
|
|
||
|
|
from fastapi import FastAPI, Request
|
||
|
|
from fastapi.middleware.cors import CORSMiddleware
|
||
|
|
from fastapi.middleware.gzip import GZipMiddleware
|
||
|
|
from fastapi.responses import JSONResponse
|
||
|
|
|
||
|
|
from logging_config import setup_logging
|
||
|
|
from middleware.request_logger import RequestLoggerMiddleware
|
||
|
|
from auth.router import router as auth_router
|
||
|
|
from auth.service import seed_default_admin
|
||
|
|
from routers import risk, alerts, analysis, insights, reports, cases, geocoded, grid
|
||
|
|
|
||
|
|
|
||
|
|
setup_logging()
|
||
|
|
seed_default_admin()
|
||
|
|
|
||
|
|
|
||
|
|
app = FastAPI(
|
||
|
|
title="CBPOA Risk Assessment API",
|
||
|
|
description="API for CBPOA health risk assessment and alert management",
|
||
|
|
version="1.0.0",
|
||
|
|
)
|
||
|
|
|
||
|
|
app.add_middleware(RequestLoggerMiddleware)
|
||
|
|
app.add_middleware(GZipMiddleware, minimum_size=1000)
|
||
|
|
|
||
|
|
logger = logging.getLogger("cbpoa.main")
|
||
|
|
|
||
|
|
|
||
|
|
@app.exception_handler(Exception)
|
||
|
|
async def global_exception_handler(request: Request, exc: Exception):
|
||
|
|
logger.exception("Unhandled exception on %s %s", request.method, request.url.path)
|
||
|
|
return JSONResponse(status_code=500, content={"detail": "Internal server error"})
|
||
|
|
|
||
|
|
cors_origins = os.getenv("CORS_ORIGINS", "http://localhost:3000,http://localhost:5173,http://127.0.0.1:3000,http://127.0.0.1:5173").split(",")
|
||
|
|
|
||
|
|
app.add_middleware(
|
||
|
|
CORSMiddleware,
|
||
|
|
allow_origins=cors_origins,
|
||
|
|
allow_credentials=True,
|
||
|
|
allow_methods=["*"],
|
||
|
|
allow_headers=["*"],
|
||
|
|
)
|
||
|
|
|
||
|
|
|
||
|
|
app.include_router(auth_router)
|
||
|
|
app.include_router(risk.router)
|
||
|
|
app.include_router(alerts.router)
|
||
|
|
app.include_router(analysis.router)
|
||
|
|
app.include_router(insights.router)
|
||
|
|
app.include_router(reports.router)
|
||
|
|
app.include_router(cases.router)
|
||
|
|
app.include_router(geocoded.router)
|
||
|
|
app.include_router(grid.router)
|
||
|
|
|
||
|
|
|
||
|
|
@app.get("/")
|
||
|
|
async def root():
|
||
|
|
"""Root endpoint - API health check"""
|
||
|
|
return {
|
||
|
|
"message": "CBPOA Risk Assessment API",
|
||
|
|
"version": "1.0.0",
|
||
|
|
"status": "running"
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
@app.get("/health")
|
||
|
|
async def health_check():
|
||
|
|
"""Health check endpoint for monitoring"""
|
||
|
|
return {"status": "healthy"}
|