debug
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import json
|
||||
from pathlib import Path
|
||||
|
||||
from pydantic import field_validator
|
||||
from pydantic_settings import BaseSettings, SettingsConfigDict
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@ class Settings(BaseSettings):
|
||||
api_prefix: str = "/api/v1"
|
||||
api_host: str = "0.0.0.0"
|
||||
api_port: int = 8100
|
||||
cors_origins: list[str] = ["http://127.0.0.1:3200", "http://localhost:3200"]
|
||||
cors_origins: str = "http://127.0.0.1:3200,http://localhost:3200"
|
||||
db_host: str = "127.0.0.1"
|
||||
db_port: int = 5432
|
||||
db_database: str = "domain"
|
||||
@@ -43,14 +43,25 @@ class Settings(BaseSettings):
|
||||
sync_batch_size: int = 200
|
||||
sync_poll_interval_seconds: int = 30
|
||||
|
||||
@field_validator("cors_origins", mode="before")
|
||||
@classmethod
|
||||
def parse_cors_origins(cls, value: object) -> object:
|
||||
if isinstance(value, str):
|
||||
if value.strip().startswith("["):
|
||||
return value
|
||||
return [item.strip() for item in value.split(",") if item.strip()]
|
||||
return value
|
||||
@property
|
||||
def cors_origins_list(self) -> list[str]:
|
||||
value = self.cors_origins
|
||||
if isinstance(value, list):
|
||||
return [str(item).strip() for item in value if str(item).strip()]
|
||||
if not isinstance(value, str):
|
||||
return []
|
||||
stripped = value.strip()
|
||||
if not stripped:
|
||||
return []
|
||||
if stripped.startswith("["):
|
||||
try:
|
||||
parsed = json.loads(stripped)
|
||||
except json.JSONDecodeError:
|
||||
pass
|
||||
else:
|
||||
if isinstance(parsed, list):
|
||||
return [str(item).strip() for item in parsed if str(item).strip()]
|
||||
return [item.strip() for item in stripped.split(",") if item.strip()]
|
||||
|
||||
model_config = SettingsConfigDict(
|
||||
env_file=(str(API_ENV_FILE), str(ENV_FILE)),
|
||||
|
||||
@@ -26,7 +26,7 @@ app = FastAPI(
|
||||
|
||||
app.add_middleware(
|
||||
CORSMiddleware,
|
||||
allow_origins=app_settings.cors_origins,
|
||||
allow_origins=app_settings.cors_origins_list,
|
||||
allow_credentials=True,
|
||||
allow_methods=["*"],
|
||||
allow_headers=["*"],
|
||||
|
||||
Reference in New Issue
Block a user