Refactor route handling in panelctl.sh and update caddy configuration for improved route management
Co-authored-by: Copilot <copilot@github.com>
This commit is contained in:
parent
c1aa44c04e
commit
5c67fecd2d
2 changed files with 33 additions and 9 deletions
|
|
@ -43,9 +43,8 @@ INDEX_HTML = """<!doctype html>
|
||||||
}
|
}
|
||||||
|
|
||||||
.wrap {
|
.wrap {
|
||||||
max-width: 980px;
|
|
||||||
margin: 0 auto;
|
margin: 0 auto;
|
||||||
padding: 28px 16px 40px;
|
padding: 28px 28px 40px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.hero {
|
.hero {
|
||||||
|
|
|
||||||
39
panelctl.sh
39
panelctl.sh
|
|
@ -76,7 +76,7 @@ app_volume_dir() {
|
||||||
|
|
||||||
app_route_file() {
|
app_route_file() {
|
||||||
local name="$1"
|
local name="$1"
|
||||||
echo "${ROUTES_DIR}/${name}.caddy"
|
echo "${ROUTES_DIR}/routes.caddy"
|
||||||
}
|
}
|
||||||
|
|
||||||
load_app() {
|
load_app() {
|
||||||
|
|
@ -248,12 +248,29 @@ cmd_render_route() {
|
||||||
auth_block="${FORWARD_AUTH_BLOCK}"
|
auth_block="${FORWARD_AUTH_BLOCK}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
cat >"${APP_ROUTE_FILE}" <<EOF
|
# Append to aggregate routes file (idempotent: remove stale block first).
|
||||||
${APP_DOMAIN} {
|
local tmp
|
||||||
${auth_block} reverse_proxy ${APP_UPSTREAM}
|
tmp="$(mktemp)"
|
||||||
}
|
|
||||||
EOF
|
|
||||||
|
|
||||||
|
# Strip any existing block for this app from the aggregate file.
|
||||||
|
if [[ -f "${APP_ROUTE_FILE}" ]]; then
|
||||||
|
grep -v "^# route:${name}:" "${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}"
|
echo "rendered route ${APP_ROUTE_FILE}"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -306,7 +323,15 @@ cmd_remove() {
|
||||||
|
|
||||||
run_compose -f "${APP_COMPOSE_FILE}" down || true
|
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}"
|
rm -rf "${APP_STACK_DIR}"
|
||||||
|
|
||||||
if [[ "${keep_volumes}" != "--keep-volumes" ]]; then
|
if [[ "${keep_volumes}" != "--keep-volumes" ]]; then
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue