From 9fd882c9854c8aa194f8188d9a6890110ff412f2 Mon Sep 17 00:00:00 2001 From: Kalinka George Date: Tue, 4 Apr 2023 17:59:29 +0800 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20feat:=20Added=20cors=20settings?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/rest_api/api.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/core/rest_api/api.py b/core/rest_api/api.py index d961d1a..a20b069 100644 --- a/core/rest_api/api.py +++ b/core/rest_api/api.py @@ -5,12 +5,14 @@ import fastapi_gateway_auto_generate from core.config.envs import DICT_ENVS +from fastapi.middleware.cors import CORSMiddleware class API: def __init__(self): self.__app: FastAPI = FastAPI(debug=True) self.__init_routes() + self.__cors_settings() config: fastapi_gateway_auto_generate.Config = fastapi_gateway_auto_generate.Config( fast_api_app=self.__app, @@ -22,6 +24,19 @@ def __init__(self): def __init_routes(self): logger.success("Routers initialized") + def __cors_settings(self): + origins = ["*"] + + self.__app.add_middleware( + CORSMiddleware, + allow_origins=origins, + allow_credentials=True, + allow_methods=["*"], + allow_headers=["*"], + ) + + logger.success("Cors settings are installed") + def run_uvicorn_server(self): run_uvicorn_loguru( uvicorn.Config(