check caddy admin API on page load, warn if unreachable
This commit is contained in:
1 parent
b91f8da190
commit
febe18b431
1 file changed
+22
-2
+22
-2
@@ -90,6 +90,16 @@ if (isset($_GET['action'])) {
|
|||||||
|
|
||||||
switch ($_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':
|
case 'load':
|
||||||
$raw = file_exists(CADDYFILE_PATH) ? file_get_contents(CADDYFILE_PATH) : '';
|
$raw = file_exists(CADDYFILE_PATH) ? file_get_contents(CADDYFILE_PATH) : '';
|
||||||
echo json_encode(['ok' => true, 'data' => parseCaddyfile($raw)]);
|
echo json_encode(['ok' => true, 'data' => parseCaddyfile($raw)]);
|
||||||
@@ -469,14 +479,24 @@ let sites = [];
|
|||||||
// ─── Init ────────────────────────────────────────────────────────────────────
|
// ─── Init ────────────────────────────────────────────────────────────────────
|
||||||
async function init() {
|
async function init() {
|
||||||
try {
|
try {
|
||||||
const r = await fetch('?action=load');
|
const [loadRes, adminRes] = await Promise.all([
|
||||||
const d = await r.json();
|
fetch('?action=load'),
|
||||||
|
fetch('?action=check_admin'),
|
||||||
|
]);
|
||||||
|
const d = await loadRes.json();
|
||||||
if (!d.ok) throw new Error(d.error);
|
if (!d.ok) throw new Error(d.error);
|
||||||
document.getElementById('global-editor').value = d.data.global;
|
document.getElementById('global-editor').value = d.data.global;
|
||||||
sites = d.data.sites;
|
sites = d.data.sites;
|
||||||
syncAdminToggle();
|
syncAdminToggle();
|
||||||
renderSites();
|
renderSites();
|
||||||
|
|
||||||
|
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', '');
|
setStatus('Ready', '');
|
||||||
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
setStatus('Load error: ' + e.message, 'error');
|
setStatus('Load error: ' + e.message, 'error');
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user