From 17ac5953ae2bda0e78fa68496478b22df6b8b4aa Mon Sep 17 00:00:00 2001 From: Jakub Dorfman Date: Sun, 26 Apr 2026 20:41:56 +0200 Subject: [PATCH] Refactor route handling in panelctl.sh and update caddy configuration for improved route management Co-authored-by: Copilot --- caddy.nix | 2 +- configuration.nix | 2 +- panel/panel-api.py | 3 +-- panel/panelctl.sh | 39 ++++++++++++++++++++++++++++++++------- 4 files changed, 35 insertions(+), 11 deletions(-) diff --git a/caddy.nix b/caddy.nix index 964951a..036e9dd 100755 --- a/caddy.nix +++ b/caddy.nix @@ -5,7 +5,7 @@ email = "admin@srazka.com"; extraConfig = '' # Generated app routes from the panel backend. - import /home/reudy/containers/routes/*.caddy + import /home/reudy/containers/routes/routes.caddy ''; # Authelia's own login portal diff --git a/configuration.nix b/configuration.nix index c97b1ec..122a557 100644 --- a/configuration.nix +++ b/configuration.nix @@ -43,7 +43,7 @@ "d /home/reudy/containers 0750 reudy panelroutes -" "d /home/reudy/containers/stacks 0750 reudy panelroutes -" "d /home/reudy/containers/volumes 0750 reudy panelroutes -" - "d /home/reudy/containers/routes 0750 reudy panelroutes -" + "d /home/reudy/containers/routes 0755 reudy panelroutes -" "d /home/reudy/containers/state 0750 reudy panelroutes -" "d /home/reudy/containers/state/apps 0750 reudy panelroutes -" "f /home/reudy/containers/routes/_placeholder.caddy 0640 reudy panelroutes -" diff --git a/panel/panel-api.py b/panel/panel-api.py index 7a00e65..090b88d 100644 --- a/panel/panel-api.py +++ b/panel/panel-api.py @@ -43,9 +43,8 @@ INDEX_HTML = """ } .wrap { - max-width: 980px; margin: 0 auto; - padding: 28px 16px 40px; + padding: 28px 28px 40px; } .hero { diff --git a/panel/panelctl.sh b/panel/panelctl.sh index 9b24555..446b22a 100644 --- a/panel/panelctl.sh +++ b/panel/panelctl.sh @@ -76,7 +76,7 @@ app_volume_dir() { app_route_file() { local name="$1" - echo "${ROUTES_DIR}/${name}.caddy" + echo "${ROUTES_DIR}/routes.caddy" } load_app() { @@ -248,12 +248,29 @@ cmd_render_route() { auth_block="${FORWARD_AUTH_BLOCK}" fi - cat >"${APP_ROUTE_FILE}" <"${tmp}" + else + printf "" >"${tmp}" + fi + + { + printf "# route:%s:start\n" "${name}" + printf "%s {\n" "${APP_DOMAIN}" + if [[ -n "${auth_block}" ]]; then + printf "%s\n" "${auth_block}" + fi + printf " reverse_proxy %s\n" "${APP_UPSTREAM}" + printf "}\n" + printf "# route:%s:end\n" "${name}" + } >>"${tmp}" + + mv "${tmp}" "${APP_ROUTE_FILE}" echo "rendered route ${APP_ROUTE_FILE}" } @@ -306,7 +323,15 @@ cmd_remove() { run_compose -f "${APP_COMPOSE_FILE}" down || true - rm -f "${APP_ROUTE_FILE}" "$(app_manifest "${name}")" + # Remove this app's block from the aggregate routes file. + if [[ -f "${APP_ROUTE_FILE}" ]]; then + local tmp + tmp="$(mktemp)" + grep -v "^# route:${name}:" "${APP_ROUTE_FILE}" >"${tmp}" + mv "${tmp}" "${APP_ROUTE_FILE}" + fi + + rm -f "$(app_manifest "${name}")" rm -rf "${APP_STACK_DIR}" if [[ "${keep_volumes}" != "--keep-volumes" ]]; then