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.
This commit is contained in:
Brückner
2026-06-08 13:17:48 +02:00
parent f66b1ca456
commit 250c347f58
2 changed files with 7 additions and 2 deletions

View File

@ -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());
// -------------------------------------------------------------