解决跨越问题
parent
6699538e0a
commit
245616d15b
|
|
@ -1,38 +1,40 @@
|
||||||
"""
|
"""
|
||||||
Application configuration
|
Application configuration
|
||||||
"""
|
"""
|
||||||
from typing import Union
|
from typing import Union, Any
|
||||||
from pydantic_settings import BaseSettings, SettingsConfigDict
|
from pydantic_settings import BaseSettings, SettingsConfigDict
|
||||||
from pydantic import Field, field_validator, ValidationInfo
|
from pydantic import Field, field_validator, ValidationInfo
|
||||||
|
|
||||||
|
|
||||||
def parse_cors_origins(v: Union[str, list]) -> list[str]:
|
|
||||||
"""Parse CORS origins from comma-separated string or list"""
|
|
||||||
if isinstance(v, str):
|
|
||||||
# Parse comma-separated string
|
|
||||||
return [origin.strip() for origin in v.split(',') if origin.strip()]
|
|
||||||
if isinstance(v, list):
|
|
||||||
return v
|
|
||||||
return ["*"]
|
|
||||||
|
|
||||||
|
|
||||||
class Settings(BaseSettings):
|
class Settings(BaseSettings):
|
||||||
"""Application settings"""
|
"""Application settings"""
|
||||||
|
|
||||||
model_config = SettingsConfigDict(env_file=".env")
|
model_config = SettingsConfigDict(
|
||||||
|
env_file=".env",
|
||||||
|
# Don't try to parse json for environment variables
|
||||||
|
env_parse_none_str=None,
|
||||||
|
)
|
||||||
|
|
||||||
# Application
|
# Application
|
||||||
app_name: str = "Cosmo - Deep Space Explorer"
|
app_name: str = "Cosmo - Deep Space Explorer"
|
||||||
api_prefix: str = "/api"
|
api_prefix: str = "/api"
|
||||||
|
|
||||||
# CORS settings - allow all origins for development (IP access support)
|
# CORS settings - stored as string in env, converted to list
|
||||||
cors_origins: list[str] = Field(default_factory=lambda: ["*"])
|
cors_origins: Union[str, list[str]] = "*"
|
||||||
|
|
||||||
@field_validator('cors_origins', mode='before')
|
@field_validator('cors_origins', mode='before')
|
||||||
@classmethod
|
@classmethod
|
||||||
def validate_cors_origins(cls, v: Union[str, list], info: ValidationInfo) -> list[str]:
|
def validate_cors_origins(cls, v: Any) -> list[str]:
|
||||||
"""Parse CORS origins from comma-separated string or JSON array"""
|
"""Parse CORS origins from comma-separated string or JSON array"""
|
||||||
return parse_cors_origins(v)
|
if v is None:
|
||||||
|
return ["*"]
|
||||||
|
if isinstance(v, str):
|
||||||
|
# Parse comma-separated string
|
||||||
|
origins = [origin.strip() for origin in v.split(',') if origin.strip()]
|
||||||
|
return origins if origins else ["*"]
|
||||||
|
if isinstance(v, list):
|
||||||
|
return v
|
||||||
|
return ["*"]
|
||||||
|
|
||||||
# Cache settings
|
# Cache settings
|
||||||
cache_ttl_days: int = 3
|
cache_ttl_days: int = 3
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue