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:
@ -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 ${REPO_BRANCH} '${CLONE_URL}' ${APP_DIR}"
|
||||||
run "sudo -u ghostgrid git clone --branch ${DEV_BRANCH} '${CLONE_URL}' ${DEV_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 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_ok "Repositories cloned (main + dev)"
|
||||||
|
|
||||||
msg_info "Creating .env file for each instance"
|
msg_info "Creating .env file for each instance"
|
||||||
|
|||||||
@ -89,7 +89,7 @@ function buildCaddyfile(): string {
|
|||||||
return lines.join('\n');
|
return lines.join('\n');
|
||||||
}
|
}
|
||||||
|
|
||||||
function importCaddyfileRoutes(userId: string): void {
|
function importCaddyfileRoutes(userId?: string): void {
|
||||||
if (getCaddyRoutes().length > 0) return;
|
if (getCaddyRoutes().length > 0) return;
|
||||||
const caddyfilePath = '/etc/caddy/Caddyfile';
|
const caddyfilePath = '/etc/caddy/Caddyfile';
|
||||||
if (!fs.existsSync(caddyfilePath)) return;
|
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 (?, ?, ?, ?, ?, ?)')
|
db.prepare('INSERT INTO logs (id, timestamp, type, message, deviceId, userId) VALUES (?, ?, ?, ?, ?, ?)')
|
||||||
.run(uid('log'), new Date().toISOString(), 'system',
|
.run(uid('log'), new Date().toISOString(), 'system',
|
||||||
`Caddy: imported ${imported.length} route(s) from Caddyfile — ${imported.join(', ')}`,
|
`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');
|
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());
|
app.use(express.json());
|
||||||
|
|
||||||
// -------------------------------------------------------------
|
// -------------------------------------------------------------
|
||||||
|
|||||||
Reference in New Issue
Block a user