feat(config): 新增环境变量文件
This commit is contained in:
17
config.py
17
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 = '<KEY>'
|
||||
APP_SECRET: str = '<KEY>'
|
||||
|
||||
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()
|
||||
|
||||
Reference in New Issue
Block a user