| 12345678910111213141516171819202122232425262728293031323334353637383940 |
- # app/main.py
- from fastapi import FastAPI
- from fastapi.middleware.cors import CORSMiddleware
- from app.core.config import settings
- from app.api.endpoints import router
- from app.core.exception_handler import register_exception_handlers
- app = FastAPI(
- title=settings.PROJECT_NAME,
- openapi_url=f"{settings.API_V1_STR}/openapi.json"
- )
- # 注册全局异常处理器(必须在路由注册之前)
- register_exception_handlers(app)
- # CORS 配置
- cors_origins = settings.CORS_ORIGINS.split(",") if settings.CORS_ORIGINS != "*" else ["*"]
- app.add_middleware(
- CORSMiddleware,
- allow_origins=[origin.strip() for origin in cors_origins],
- allow_credentials=True,
- allow_methods=["*"],
- allow_headers=["*"],
- )
- # 注册路由
- app.include_router(router, prefix=settings.API_V1_STR) # 前缀 /api
- @app.get("/")
- async def root():
- return {"message": "MinIO FileManager Backend is Running"}
- @app.get("/health")
- async def health_check():
- """健康检查端点"""
- return {"status": "healthy"}
- if __name__ == "__main__":
- import uvicorn
- uvicorn.run("app.main:app", host="0.0.0.0", port=9002, reload=True)
|