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>
This commit is contained in:
2026-02-24 07:58:59 +01:00
parent 92912c5890
commit 9a59b38fd6
3 changed files with 13 additions and 7 deletions
+6 -5
View File
@@ -8,8 +8,9 @@ import requests
class MealieClient:
"""Thin wrapper around the Mealie REST API."""
def __init__(self, base_url: str, api_key: str):
def __init__(self, base_url: str, api_key: str, api_url: str = ""):
self.base_url = base_url.rstrip("/")
self.api_url = api_url.rstrip("/") if api_url else self.base_url
self.session = requests.Session()
self.session.headers.update({
"Authorization": f"Bearer {api_key}",
@@ -22,7 +23,7 @@ class MealieClient:
def test_connection(self) -> dict:
"""Return Mealie app info or raise on failure."""
r = self.session.get(f"{self.base_url}/api/app/about", timeout=10)
r = self.session.get(f"{self.api_url}/api/app/about", timeout=10)
r.raise_for_status()
return r.json()
@@ -34,7 +35,7 @@ class MealieClient:
"""
# Step 1: create stub
r = self.session.post(
f"{self.base_url}/api/recipes",
f"{self.api_url}/api/recipes",
json={"name": recipe["title"]},
timeout=15,
)
@@ -44,7 +45,7 @@ class MealieClient:
# Step 2: build full payload and PATCH
payload = self._build_payload(recipe)
r = self.session.patch(
f"{self.base_url}/api/recipes/{slug}",
f"{self.api_url}/api/recipes/{slug}",
json=payload,
timeout=15,
)
@@ -107,7 +108,7 @@ class MealieClient:
"image": (f"recipe.{ext}", io.BytesIO(img_resp.content), content_type),
}
r = self.session.put(
f"{self.base_url}/api/recipes/{slug}/image",
f"{self.api_url}/api/recipes/{slug}/image",
files=files,
timeout=30,
)