main.py 794 B

123456789101112131415161718192021222324252627282930
  1. # app/main.py
  2. from fastapi import FastAPI
  3. from fastapi.middleware.cors import CORSMiddleware
  4. from app.core.config import settings
  5. from app.api.endpoints import router
  6. app = FastAPI(
  7. title=settings.PROJECT_NAME,
  8. openapi_url=f"{settings.API_V1_STR}/openapi.json"
  9. )
  10. # CORS 配置
  11. app.add_middleware(
  12. CORSMiddleware,
  13. allow_origins=["*"], # 生产环境建议改为具体的 ["http://localhost:8080"]
  14. allow_credentials=True,
  15. allow_methods=["*"],
  16. allow_headers=["*"],
  17. )
  18. # 注册路由
  19. app.include_router(router, prefix=settings.API_V1_STR) # 前缀 /api
  20. @app.get("/")
  21. async def root():
  22. return {"message": "MinIO FileManager Backend is Running"}
  23. if __name__ == "__main__":
  24. import uvicorn
  25. uvicorn.run("app.main:app", host="0.0.0.0", port=8080, reload=True)