From 250c347f5871abaf2b0451362f4a68d22fb7ecec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Br=C3=BCckner?= Date: Mon, 8 Jun 2026 13:17:48 +0200 Subject: [PATCH] feat(caddy): import Caddyfile routes on startup if table is empty On every startup, if Caddy is already enabled but the caddy table has no routes (e.g. after a re-deploy), importCaddyfileRoutes() is called so the static GhostGrid entries from /etc/caddy/Caddyfile are seeded automatically. Also ensures deploy.sh is executable via proxmox-ghostgrid.sh. --- deploy/proxmox-ghostgrid.sh | 1 + server.ts | 8 ++++++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/deploy/proxmox-ghostgrid.sh b/deploy/proxmox-ghostgrid.sh index 268b652..a506730 100644 --- a/deploy/proxmox-ghostgrid.sh +++ b/deploy/proxmox-ghostgrid.sh @@ -183,6 +183,7 @@ fi run "sudo -u ghostgrid git clone --branch ${REPO_BRANCH} '${CLONE_URL}' ${APP_DIR}" run "sudo -u ghostgrid git clone --branch ${DEV_BRANCH} '${CLONE_URL}' ${DEV_DIR}" run "chmod 600 ${APP_DIR}/.git/config ${DEV_DIR}/.git/config" +run "chmod +x ${APP_DIR}/deploy/deploy.sh ${DEV_DIR}/deploy/deploy.sh" msg_ok "Repositories cloned (main + dev)" msg_info "Creating .env file for each instance" diff --git a/server.ts b/server.ts index aa8e08c..6c76a73 100644 --- a/server.ts +++ b/server.ts @@ -89,7 +89,7 @@ function buildCaddyfile(): string { return lines.join('\n'); } -function importCaddyfileRoutes(userId: string): void { +function importCaddyfileRoutes(userId?: string): void { if (getCaddyRoutes().length > 0) return; const caddyfilePath = '/etc/caddy/Caddyfile'; if (!fs.existsSync(caddyfilePath)) return; @@ -123,7 +123,7 @@ function importCaddyfileRoutes(userId: string): void { db.prepare('INSERT INTO logs (id, timestamp, type, message, deviceId, userId) VALUES (?, ?, ?, ?, ?, ?)') .run(uid('log'), new Date().toISOString(), 'system', `Caddy: imported ${imported.length} route(s) from Caddyfile — ${imported.join(', ')}`, - null, userId); + null, userId ?? null); } } @@ -154,6 +154,10 @@ async function startServer() { console.log('[Init] Default admin user created — login: admin@ghostgrid.local / admin'); } + if (getSetting('caddy_enabled') === 'true' && getCaddyRoutes().length === 0) { + importCaddyfileRoutes(); + } + app.use(express.json()); // -------------------------------------------------------------