mirror of
https://github.com/fastapi/full-stack-fastapi-template.git
synced 2026-11-03 12:29:42 +00:00
7f8bfc8faa
not tested / updated yet
27 lines
727 B
Python
27 lines
727 B
Python
from fastapi import FastAPI
|
|
from starlette.middleware.cors import CORSMiddleware
|
|
|
|
from app.api.api_v1.api import api_router
|
|
from app.core.config import API_V1_STR, BACKEND_CORS_ORIGINS, PROJECT_NAME
|
|
|
|
app = FastAPI(title=PROJECT_NAME, openapi_url="/api/v1/openapi.json")
|
|
|
|
# CORS
|
|
origins = []
|
|
|
|
# Set all CORS enabled origins
|
|
if BACKEND_CORS_ORIGINS:
|
|
origins_raw = BACKEND_CORS_ORIGINS.split(",")
|
|
for origin in origins_raw:
|
|
use_origin = origin.strip()
|
|
origins.append(use_origin)
|
|
app.add_middleware(
|
|
CORSMiddleware,
|
|
allow_origins=origins,
|
|
allow_credentials=True,
|
|
allow_methods=["*"],
|
|
allow_headers=["*"],
|
|
),
|
|
|
|
app.include_router(api_router, prefix=API_V1_STR)
|