main.py 613 B

123456789101112131415161718192021
  1. from fastapi import FastAPI
  2. from starlette.middleware.cors import CORSMiddleware
  3. from app.api.api_v1.api import api_router
  4. from app.core.config import settings
  5. app = FastAPI(
  6. title=settings.PROJECT_NAME, openapi_url=f"{settings.API_V1_STR}/openapi.json"
  7. )
  8. # Set all CORS enabled origins
  9. if settings.BACKEND_CORS_ORIGINS:
  10. app.add_middleware(
  11. CORSMiddleware,
  12. allow_origins=[str(origin) for origin in settings.BACKEND_CORS_ORIGINS],
  13. allow_credentials=True,
  14. allow_methods=["*"],
  15. allow_headers=["*"],
  16. )
  17. app.include_router(api_router, prefix=settings.API_V1_STR)