feat(server): modularize backend and admin console
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
from pathlib import Path
|
||||
import os
|
||||
|
||||
from dotenv import load_dotenv
|
||||
|
||||
|
||||
BASE_DIR = Path(__file__).resolve().parents[2]
|
||||
ENV_FILE_PATH = Path(os.getenv("ENV_FILE_PATH", str(BASE_DIR / ".env"))).expanduser()
|
||||
if not ENV_FILE_PATH.is_absolute():
|
||||
ENV_FILE_PATH = BASE_DIR / ENV_FILE_PATH
|
||||
|
||||
load_dotenv(ENV_FILE_PATH)
|
||||
|
||||
|
||||
def env_bool(name: str, default: bool = False) -> bool:
|
||||
value = os.getenv(name)
|
||||
return default if value is None else value.strip().lower() in {"1", "true", "yes", "on"}
|
||||
|
||||
|
||||
def configured_path(name: str, default: str) -> Path:
|
||||
path = Path(os.getenv(name, default)).expanduser()
|
||||
return path if path.is_absolute() else BASE_DIR / path
|
||||
|
||||
|
||||
class Settings:
|
||||
"""Centralized settings facade used during the backend template migration."""
|
||||
|
||||
server_host = os.getenv("SERVER_HOST", "0.0.0.0")
|
||||
server_port = int(os.getenv("SERVER_PORT", "8000"))
|
||||
service_title = os.getenv("SERVICE_TITLE", "软件自动升级服务")
|
||||
admin_token = os.getenv("ADMIN_TOKEN", "").strip()
|
||||
|
||||
|
||||
settings = Settings()
|
||||
Reference in New Issue
Block a user