Files
recipe-importer/app/config.py
T
admin 9a59b38fd6 fix: add MEALIE_INTERNAL_URL env var for Docker-to-Docker API calls
When deployed behind Cloudflare Tunnel, requests from the container to
the external Mealie URL fail with 530 (hairpin). MEALIE_INTERNAL_URL
lets the container use the Docker-internal address (e.g. http://mealie:9000)
for API calls while keeping the external URL for browser links.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-24 07:58:59 +01:00

43 lines
1.2 KiB
Python

"""Configuration management — persists Mealie connection settings to a JSON file."""
import json
import os
from pathlib import Path
DATA_DIR = Path(os.environ.get("DATA_DIR", "/data"))
CONFIG_FILE = DATA_DIR / "config.json"
# Optional internal URL for Docker-to-Docker API calls (avoids Cloudflare hairpin).
# The user-facing mealie_url is still used for browser links.
MEALIE_INTERNAL_URL = os.environ.get("MEALIE_INTERNAL_URL", "").strip().rstrip("/")
_DEFAULTS = {
"mealie_url": "",
"mealie_api_key": "",
}
def _ensure_dir():
DATA_DIR.mkdir(parents=True, exist_ok=True)
def load() -> dict:
"""Return the current config dict, merged with defaults."""
cfg = dict(_DEFAULTS)
if CONFIG_FILE.exists():
try:
with open(CONFIG_FILE, "r", encoding="utf-8") as f:
cfg.update(json.load(f))
except (json.JSONDecodeError, OSError):
pass
return cfg
def save(cfg: dict):
"""Atomically persist *cfg* to disk."""
_ensure_dir()
tmp = CONFIG_FILE.with_suffix(".tmp")
with open(tmp, "w", encoding="utf-8") as f:
json.dump(cfg, f, indent=2, ensure_ascii=False)
tmp.replace(CONFIG_FILE)