origins в env
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
# backend (src)
|
APP__ORIGINS=["http://locahost:3000"]
|
||||||
DB__URL=postgres://user:password@localhost:5432/tgex
|
DB__URL=postgres://user:password@localhost:5432/tgex
|
||||||
|
|
||||||
LOGGER__APP_NAME=tgex-backend
|
LOGGER__APP_NAME=tgex-backend
|
||||||
@@ -14,12 +14,10 @@ S3__ACCESS_KEY_ID=user
|
|||||||
S3__SECRET_ACCESS_KEY=password
|
S3__SECRET_ACCESS_KEY=password
|
||||||
S3__BUCKET_NAME=tgex-files
|
S3__BUCKET_NAME=tgex-files
|
||||||
|
|
||||||
# tg_bot (telegram_bot)
|
|
||||||
TELEGRAM__TOKEN=your_bot_token_here
|
TELEGRAM__TOKEN=your_bot_token_here
|
||||||
BACKEND__BASE_URL=http://localhost:8000
|
BACKEND__BASE_URL=http://localhost:8000
|
||||||
LOGIN_URL=https://app.example.com/api/v1/auth/complete?token=
|
LOGIN_URL=https://app.example.com/api/v1/auth/complete?token=
|
||||||
|
|
||||||
# tg_parser (tg_parser)
|
|
||||||
TELEGRAM__API_ID=123456
|
TELEGRAM__API_ID=123456
|
||||||
TELEGRAM__API_HASH=your_api_hash_here
|
TELEGRAM__API_HASH=your_api_hash_here
|
||||||
TELEGRAM__SESSION_FILE=/data/tg_parser.json
|
TELEGRAM__SESSION_FILE=/data/tg_parser.json
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
from pydantic import BaseModel
|
import json
|
||||||
|
|
||||||
|
from pydantic import BaseModel, field_validator
|
||||||
from pydantic_settings import BaseSettings, SettingsConfigDict
|
from pydantic_settings import BaseSettings, SettingsConfigDict
|
||||||
|
|
||||||
from shared.config_helper import load_settings
|
from shared.config_helper import load_settings
|
||||||
@@ -13,9 +15,23 @@ class ParserConfig(BaseModel):
|
|||||||
URL: str
|
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):
|
class Settings(BaseSettings):
|
||||||
model_config = SettingsConfigDict(env_file='.env', case_sensitive=False, env_nested_delimiter='__')
|
model_config = SettingsConfigDict(env_file='.env', case_sensitive=False, env_nested_delimiter='__')
|
||||||
|
|
||||||
|
app: AppConfig
|
||||||
db: DatabaseConfig
|
db: DatabaseConfig
|
||||||
logger: LoggerConfig
|
logger: LoggerConfig
|
||||||
telegram: TelegramConfig
|
telegram: TelegramConfig
|
||||||
|
|||||||
@@ -63,11 +63,7 @@ app = FastAPI(
|
|||||||
|
|
||||||
app.add_middleware(
|
app.add_middleware(
|
||||||
CORSMiddleware,
|
CORSMiddleware,
|
||||||
allow_origins=[
|
allow_origins=settings.app.ORIGINS,
|
||||||
'https://app.tgexchange.ru',
|
|
||||||
'http://app.tgexchange.ru',
|
|
||||||
'http://localhost:3000',
|
|
||||||
],
|
|
||||||
allow_credentials=True,
|
allow_credentials=True,
|
||||||
allow_methods=['*'],
|
allow_methods=['*'],
|
||||||
allow_headers=['*'],
|
allow_headers=['*'],
|
||||||
|
|||||||
Reference in New Issue
Block a user