From febe18b431f2b8c61c9139bc3f3dd67a860815f9 Mon Sep 17 00:00:00 2001 From: Daniel Date: Mon, 6 Apr 2026 22:30:50 +0200 Subject: [PATCH] check caddy admin API on page load, warn if unreachable --- app/index.php | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/app/index.php b/app/index.php index 2ed2516..3b90b3f 100644 --- a/app/index.php +++ b/app/index.php @@ -90,6 +90,16 @@ if (isset($_GET['action'])) { switch ($_GET['action']) { + case 'check_admin': + $ch = curl_init(rtrim(CADDY_ADMIN_URL, '/') . '/config/'); + curl_setopt_array($ch, [CURLOPT_RETURNTRANSFER => true, CURLOPT_TIMEOUT => 3]); + curl_exec($ch); + $code = curl_getinfo($ch, CURLINFO_HTTP_CODE); + $err = curl_error($ch); + curl_close($ch); + echo json_encode(['ok' => !$err && $code > 0]); + exit; + case 'load': $raw = file_exists(CADDYFILE_PATH) ? file_get_contents(CADDYFILE_PATH) : ''; echo json_encode(['ok' => true, 'data' => parseCaddyfile($raw)]); @@ -469,14 +479,24 @@ let sites = []; // ─── Init ──────────────────────────────────────────────────────────────────── async function init() { try { - const r = await fetch('?action=load'); - const d = await r.json(); + const [loadRes, adminRes] = await Promise.all([ + fetch('?action=load'), + fetch('?action=check_admin'), + ]); + const d = await loadRes.json(); if (!d.ok) throw new Error(d.error); document.getElementById('global-editor').value = d.data.global; sites = d.data.sites; syncAdminToggle(); renderSites(); - setStatus('Ready', ''); + + const admin = await adminRes.json(); + if (!admin.ok) { + setStatus('Caddy admin API unreachable', 'warn'); + toast('Caddy admin API is not reachable — deploy will fail', 'warn'); + } else { + setStatus('Ready', ''); + } } catch (e) { setStatus('Load error: ' + e.message, 'error'); }