Spaces:
Running
Running
Sync from GitHub via hub-sync
Browse files
config.py
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
| 1 |
from pydantic_settings import BaseSettings, SettingsConfigDict
|
| 2 |
|
| 3 |
|
|
@@ -8,6 +11,16 @@ class Settings(BaseSettings):
|
|
| 8 |
DEBUG: bool = False
|
| 9 |
CORS_ORIGINS: list[str] = ["http://localhost:5173"]
|
| 10 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
# Database
|
| 12 |
DATABASE_URL: str = "sqlite:///./deepshield.db"
|
| 13 |
|
|
|
|
| 1 |
+
import json
|
| 2 |
+
from typing import Any
|
| 3 |
+
from pydantic import field_validator
|
| 4 |
from pydantic_settings import BaseSettings, SettingsConfigDict
|
| 5 |
|
| 6 |
|
|
|
|
| 11 |
DEBUG: bool = False
|
| 12 |
CORS_ORIGINS: list[str] = ["http://localhost:5173"]
|
| 13 |
|
| 14 |
+
@field_validator("CORS_ORIGINS", mode="before")
|
| 15 |
+
@classmethod
|
| 16 |
+
def assemble_cors_origins(cls, v: Any) -> list[str]:
|
| 17 |
+
"""Parse CORS_ORIGINS from string (JSON or comma-separated) into a list."""
|
| 18 |
+
if isinstance(v, str) and not v.startswith("["):
|
| 19 |
+
return [i.strip() for i in v.split(",")]
|
| 20 |
+
elif isinstance(v, str) and v.startswith("["):
|
| 21 |
+
return json.loads(v)
|
| 22 |
+
return v
|
| 23 |
+
|
| 24 |
# Database
|
| 25 |
DATABASE_URL: str = "sqlite:///./deepshield.db"
|
| 26 |
|