refactor: simplify how url generation works

The URLS file is no longer necessary as urls are now generated directly from the app VHOST file.

This also moves all the url generation logic to the domains plugin.
This commit is contained in:
Jose Diaz-Gonzalez
2022-12-02 02:19:59 -05:00
parent f4f0a29446
commit edd6e476b3
23 changed files with 247 additions and 179 deletions

35
plugins/domains/domains-urls Executable file
View File

@@ -0,0 +1,35 @@
#!/usr/bin/env bash
source "$PLUGIN_AVAILABLE_PATH/domains/internal-functions"
set -eo pipefail
[[ $DOKKU_TRACE ]] && set -x
trigger-domains-domains-urls() {
declare desc="gets an app's urls"
declare trigger="domains-urls"
declare APP="$1" URL_TYPE="$2"
local urls
local SCHEME="http"
local DEFAULT_LISTEN_PORT="80"
if [[ "$(plugn trigger certs-exists "$APP")" == "true" ]]; then
SCHEME="https"
DEFAULT_LISTEN_PORT="443"
fi
urls=$(plugn trigger app-urls "$APP" "$URL_TYPE")
if [[ -n "$urls" ]]; then
if [[ "$URL_TYPE" == "url" ]]; then
echo "$urls" | tr ' ' '\n' | grep "$SCHEME://" | head -n1
else
echo "$urls" | tr ' ' '\n' | sort
fi
else
if [[ "$URL_TYPE" == "url" ]]; then
fn-domains-generate-urls "$APP" "$SCHEME" "$DEFAULT_LISTEN_PORT" | tr ' ' '\n' | grep "$SCHEME://" | head -n1
else
fn-domains-generate-urls "$APP" "$SCHEME" "$DEFAULT_LISTEN_PORT" | tr ' ' '\n' | sort
fi
fi
}
trigger-domains-domains-urls "$@"