Files
full-stack-fastapi-template/{{cookiecutter.project_slug}}/backend/app/app/main.py
T
Sebastián Ramírez 7f8bfc8faa 🎉 First commit, from couchbase generator, basic changes
not tested / updated yet
2019-02-09 19:42:36 +04:00

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)