diff --git a/app/core/config.py b/app/core/config.py index e5b20d2..e7c7a21 100644 --- a/app/core/config.py +++ b/app/core/config.py @@ -31,6 +31,8 @@ class Settings(BaseSettings): EMAIL_USE_TLS: bool = True # ================================ + host: str = 'localhost' + class Config: env_file = 'infra/.env' extra = "ignore" diff --git a/app/main.py b/app/main.py index a0da043..7991366 100644 --- a/app/main.py +++ b/app/main.py @@ -2,6 +2,7 @@ import sys from fastapi import FastAPI, applications +from fastapi.middleware.cors import CORSMiddleware from fastapi.openapi.docs import get_swagger_ui_html from sqladmin import Admin @@ -42,6 +43,15 @@ def swagger_monkey_patch(*args, **kwargs): openapi_url="/api/openapi.json", ) +origins = [f'http://{settings.host}'] + +app.add_middleware( + CORSMiddleware, + allow_origins=origins, + allow_credentials=True, + allow_methods=['*'], + allow_headers=['*'], +) if "pytest" not in sys.modules: app.add_middleware(LoggerMiddleware)