From 2218fe8ae7f38d5e11e6e3b0111a2ab15f1b33e3 Mon Sep 17 00:00:00 2001 From: xingc Date: Tue, 18 Feb 2025 21:11:48 +0800 Subject: [PATCH] =?UTF-8?q?feat(config):=20=E6=96=B0=E5=A2=9E=E7=8E=AF?= =?UTF-8?q?=E5=A2=83=E5=8F=98=E9=87=8F=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .env.dev | 24 ++++++++++++++++++++++++ config.py | 17 +++++++---------- 2 files changed, 31 insertions(+), 10 deletions(-) create mode 100644 .env.dev diff --git a/.env.dev b/.env.dev new file mode 100644 index 0000000..5b64cd1 --- /dev/null +++ b/.env.dev @@ -0,0 +1,24 @@ +# 应用配置 +ALLOWED_ORIGINS = http://127.0.0.1:3000,http://localhost:3000 + +# 身份认证 +ACCESS_SECRET_KEY = a2f718e8313bf8efcb45ef7364d040c45800f34d10f65776eef0f6584677ecd0 + +# 数据库配置 +DB_USER = card_book +DB_PASSWORD = DFCPjk4rdkca6SPE +DB_HOST = 192.168.3.4 +DB_NAME = card_book + +# redis配置 +REDIS_PASSWORD = xingc +REDIS_HOST = 192.168.3.4 +REDIS_PORT = 6379 +REDIS_DB = 0 + +# 代理 +OVERSEAS_PROXY = 'http://127.0.0.1:7890' + +# 微信 +APPID = +APP_SECRET = \ No newline at end of file diff --git a/config.py b/config.py index ffb7d3c..2370499 100644 --- a/config.py +++ b/config.py @@ -11,12 +11,10 @@ from pydantic_settings import BaseSettings, SettingsConfigDict class Settings(BaseSettings): - model_config = SettingsConfigDict(env_file='.env', env_file_encoding='utf-8') - # 基础设置 NAME: str = 'card book' PREFIX: str = NAME.lower().replace(' ', '_') - ENVIRONMENT: str = 'development' + ENVIRONMENT: str = 'dev' BASE_DIR: str = os.path.dirname(os.path.abspath(__file__)) DEBUG: bool = True @@ -65,10 +63,12 @@ class Settings(BaseSettings): APPID: str = '' APP_SECRET: str = '' + model_config = SettingsConfigDict(env_file=F'.env.{ENVIRONMENT.lower()}', env_file_encoding='utf-8') + class ProductionSettings(Settings): # 基础设置 - ENVIRONMENT: str = 'production' + ENVIRONMENT: str = 'prod' DEBUG: bool = False # 身份认证 @@ -78,9 +78,6 @@ class ProductionSettings(Settings): class DevelopmentSettings(Settings): - # 应用配置 - ALLOWED_ORIGINS: str = 'http://127.0.0.1:3000,http://localhost:3000' - # 日志配置 LOG_LEVEL: int = logging.INFO @@ -98,10 +95,10 @@ class DevelopmentSettings(Settings): def get_settings(): - env = os.environ.get('ENVIRONMENT', 'development') - if env == 'development': + env = os.environ.get('ENVIRONMENT', 'dev') + if env == 'dev': return DevelopmentSettings() - elif env == 'production': + elif env == 'prod': return ProductionSettings() return Settings()