This commit is contained in:
pika 2025-03-24 18:53:37 +01:00
parent ad913c0492
commit 429d259d06
2 changed files with 19 additions and 17 deletions

View file

@ -73,25 +73,26 @@ def parse_caddyfile():
with open(CADDYFILE_PATH, "r") as file:
content = file.read()
# Improved regex pattern to better handle different Caddyfile formats
pattern = re.compile(r"(?P<domains>[^\s{]+(?:,\s*[^\s{]+)*)\s*{[^}]*?(?:reverse_proxy|handle|respond)\s+(?P<target>https?:\/\/[\d\.]+:\d+|[\d\.]+:\d+)[^}]*?}", re.DOTALL)
# Revert to simpler pattern that was working previously
pattern = re.compile(r"(?P<domains>[^\s{]+(?:,\s*[^\s{]+)*)\s*{.*?reverse_proxy\s+(?P<target>https?:\/\/[\d\.]+:\d+|[\d\.]+:\d+).*?}", re.DOTALL)
matches = pattern.findall(content)
logger.info(f"Found {len(matches)} matches in Caddyfile")
for domains, target in matches:
for domain in re.split(r',\s*', domains):
domain = domain.strip()
if domain and not domain.lower() == "host": # Skip entries actually named "host"
if domain and domain.lower() != "host": # Skip entries named "host"
entries[domain] = target.strip()
logger.info(f"Found {len(entries)} domain entries in Caddyfile")
# Debug output to help diagnose parsing issues
logger.info(f"Extracted {len(entries)} domain entries from Caddyfile")
# Debug output of parsed entries
for domain, target in entries.items():
logger.debug(f"Parsed domain: {domain} -> {target}")
logger.debug(f"Domain: {domain} -> {target}")
except Exception as e:
logger.error(f"Error parsing Caddyfile: {e}")
# Log the error details for debugging
import traceback
logger.error(traceback.format_exc())