From 781af765a7970c40459e2c344d482b436ecf758d Mon Sep 17 00:00:00 2001 From: happycastle <41810556+happycastle114@users.noreply.github.com> Date: Wed, 22 Nov 2023 19:11:12 +0900 Subject: [PATCH] Add: CORS middleware --- main.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/main.py b/main.py index 579505e..61f00a7 100644 --- a/main.py +++ b/main.py @@ -5,7 +5,7 @@ from typing import Dict from model import MongoDB from model.ResponseType import ChartResponse, GenderInfo, PartyInfo, AgeInfo - +from fastapi.middleware.cors import CORSMiddleware @asynccontextmanager async def initMongo(app: FastAPI): @@ -18,6 +18,18 @@ async def initMongo(app: FastAPI): app = FastAPI(lifespan=initMongo, responses={404: {"description": "Not found"}}) +origin = [ + "http://localhost:5173", + "https://diversity.tech4impact.kr/" +] + +app.add_middleware( + CORSMiddleware, + allow_origins=origin, + allow_credentials=True, + allow_methods=["*"], + allow_headers=["*"], +) app.include_router(scrapResult.router) app.include_router(commonInfo.router)