added path to routing
This commit is contained in:
parent
7fd2531501
commit
85e29b8734
4 changed files with 84 additions and 30 deletions
31
panelctl.sh
31
panelctl.sh
|
|
@ -17,17 +17,18 @@ FORWARD_AUTH_BLOCK=' forward_auth 127.0.0.1:9091 {
|
|||
|
||||
validate_route_entry() {
|
||||
local entry="$1"
|
||||
# Format: domain|upstream (upstream = host:port)
|
||||
local domain="${entry%%|*}"
|
||||
local upstream="${entry#*|}"
|
||||
# Format: domain|upstream[/path] or domain|upstream (path is optional)
|
||||
IFS='|' read -r domain upstream path <<< "${entry}"
|
||||
[[ -n "${domain}" ]] || fail "empty domain in route entry '${entry}'"
|
||||
[[ -n "${upstream}" ]] || fail "empty upstream in route entry '${entry}'"
|
||||
[[ "${entry}" == *"|"* ]] || fail "route entry '${entry}' missing '|' separator (expected domain|upstream)"
|
||||
validate_single_domain "${domain}"
|
||||
# Validate upstream has a port
|
||||
local upstream_port="${upstream##*:}"
|
||||
[[ "${upstream_port}" =~ ^[0-9]+$ ]] || fail "upstream '${upstream}' missing numeric port in route entry '${entry}'"
|
||||
validate_port "${upstream_port}"
|
||||
if [[ -n "${path}" ]]; then
|
||||
[[ "${path}" == /* ]] || fail "path '${path}' must start with / in route entry '${entry}'"
|
||||
fi
|
||||
}
|
||||
|
||||
validate_routes() {
|
||||
|
|
@ -351,12 +352,24 @@ cmd_render_route() {
|
|||
IFS=',' read -ra route_entries <<< "${APP_ROUTES}"
|
||||
for entry in "${route_entries[@]}"; do
|
||||
entry="$(echo "${entry}" | xargs)"
|
||||
local domain="${entry%%|*}"
|
||||
local upstream="${entry#*|}"
|
||||
if [[ -n "${auth_block}" ]]; then
|
||||
printf "%s {\n%s reverse_proxy %s\n}\n" "${domain}" "${auth_block}" "${upstream}"
|
||||
IFS='|' read -r domain upstream path <<< "${entry}"
|
||||
# If upstream is empty (no second pipe), this is the old format
|
||||
if [[ -z "${upstream}" ]]; then
|
||||
upstream="${path}"
|
||||
path=""
|
||||
fi
|
||||
if [[ -n "${path}" ]]; then
|
||||
if [[ -n "${auth_block}" ]]; then
|
||||
printf "%s {\n%s reverse_proxy %s %s\n}\n" "${domain}" "${auth_block}" "${path}" "${upstream}"
|
||||
else
|
||||
printf "%s {\n reverse_proxy %s %s\n}\n" "${domain}" "${path}" "${upstream}"
|
||||
fi
|
||||
else
|
||||
printf "%s {\n reverse_proxy %s\n}\n" "${domain}" "${upstream}"
|
||||
if [[ -n "${auth_block}" ]]; then
|
||||
printf "%s {\n%s reverse_proxy %s\n}\n" "${domain}" "${auth_block}" "${upstream}"
|
||||
else
|
||||
printf "%s {\n reverse_proxy %s\n}\n" "${domain}" "${upstream}"
|
||||
fi
|
||||
fi
|
||||
done
|
||||
printf "# route:%s:end\n" "${name}"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue