origins в env
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
from pydantic import BaseModel
|
||||
import json
|
||||
|
||||
from pydantic import BaseModel, field_validator
|
||||
from pydantic_settings import BaseSettings, SettingsConfigDict
|
||||
|
||||
from shared.config_helper import load_settings
|
||||
@@ -13,9 +15,23 @@ class ParserConfig(BaseModel):
|
||||
URL: str
|
||||
|
||||
|
||||
class AppConfig(BaseModel):
|
||||
ORIGINS: list[str]
|
||||
|
||||
@field_validator('ORIGINS', mode='before')
|
||||
@classmethod
|
||||
def parse_origins(cls, v: str | list[str]) -> list[str]:
|
||||
if isinstance(v, list):
|
||||
return v
|
||||
if isinstance(v, str):
|
||||
return json.loads(v)
|
||||
raise ValueError('ORIGINS must be a JSON array string')
|
||||
|
||||
|
||||
class Settings(BaseSettings):
|
||||
model_config = SettingsConfigDict(env_file='.env', case_sensitive=False, env_nested_delimiter='__')
|
||||
|
||||
app: AppConfig
|
||||
db: DatabaseConfig
|
||||
logger: LoggerConfig
|
||||
telegram: TelegramConfig
|
||||
|
||||
@@ -63,11 +63,7 @@ app = FastAPI(
|
||||
|
||||
app.add_middleware(
|
||||
CORSMiddleware,
|
||||
allow_origins=[
|
||||
'https://app.tgexchange.ru',
|
||||
'http://app.tgexchange.ru',
|
||||
'http://localhost:3000',
|
||||
],
|
||||
allow_origins=settings.app.ORIGINS,
|
||||
allow_credentials=True,
|
||||
allow_methods=['*'],
|
||||
allow_headers=['*'],
|
||||
|
||||
Reference in New Issue
Block a user