diff --git a/plugins/00_dokku-standard/commands b/plugins/00_dokku-standard/commands index 35196d09b6d..364d95606f3 100755 --- a/plugins/00_dokku-standard/commands +++ b/plugins/00_dokku-standard/commands @@ -153,24 +153,27 @@ case "$1" in url | urls) [[ -z $2 ]] && echo "Please specify an app to run the command on" && exit 1 verify_app_name "$2" - APP="$2"; SCHEME="http"; SSL="$DOKKU_ROOT/$APP/tls"; WILDCARD_SSL="$DOKKU_ROOT/tls" - - if [[ -e "$SSL/server.crt" && -e "$SSL/server.key" ]] || [[ -e "$WILDCARD_SSL/server.crt" && -e "$WILDCARD_SSL/server.key" ]]; then - SCHEME="https" - fi + APP="$2"; - if [[ -f "$DOKKU_ROOT/$APP/VHOST" ]]; then + if [[ -s "$DOKKU_ROOT/$APP/URLS" ]]; then case "$1" in url) - echo "$SCHEME://$(head -n1 "$DOKKU_ROOT/$APP/VHOST")" + grep "^http" "$DOKKU_ROOT/$APP/URLS" | head -1 ;; urls) - for vhost in $(< "$DOKKU_ROOT/$APP/VHOST"); do - echo "$SCHEME://$vhost" - done + grep "^http" "$DOKKU_ROOT/$APP/URLS" ;; esac - elif [[ -f "$DOKKU_ROOT/VHOST" ]]; then + + exit 0 + fi + + SCHEME="http"; SSL="$DOKKU_ROOT/$APP/tls"; WILDCARD_SSL="$DOKKU_ROOT/tls" + if [[ -e "$SSL/server.crt" && -e "$SSL/server.key" ]] || [[ -e "$WILDCARD_SSL/server.crt" && -e "$WILDCARD_SSL/server.key" ]]; then + SCHEME="https" + fi + + if [[ -f "$DOKKU_ROOT/VHOST" ]]; then echo "$SCHEME://$(< "$DOKKU_ROOT/VHOST")" else echo "$SCHEME://$(< "$DOKKU_ROOT/HOSTNAME"):$(< "$DOKKU_ROOT/$APP/PORT")" diff --git a/plugins/nginx-vhosts/commands b/plugins/nginx-vhosts/commands index a7574587117..84724dc9506 100755 --- a/plugins/nginx-vhosts/commands +++ b/plugins/nginx-vhosts/commands @@ -18,6 +18,7 @@ case "$1" in nginx:build-config) APP="$2"; DOKKU_APP_LISTEN_PORT="$3"; DOKKU_APP_LISTEN_IP="${4}" VHOST_PATH="$DOKKU_ROOT/$APP/VHOST" + URLS_PATH="$DOKKU_ROOT/$APP/URLS" WILDCARD_SSL="$DOKKU_ROOT/tls" SSL="$DOKKU_ROOT/$APP/tls" @@ -94,6 +95,10 @@ EOF echo " Reloading nginx" restart_nginx fi + + echo "# THIS FILE IS GENERATED BY DOKKU - DO NOT EDIT, YOUR CHANGES WILL BE OVERWRITTEN" > $URLS_PATH + xargs -i echo "https://{}" <<< "${SSL_VHOSTS}" >> $URLS_PATH + xargs -i echo "http://{}" <<< "${NONSSL_VHOSTS}" >> $URLS_PATH else if [[ -f "$DOKKU_ROOT/$APP/VHOST" ]]; then dokku_log_info1 "VHOST support disabled, deleting $APP/VHOST" diff --git a/tests/unit/00_dokku-standard.bats b/tests/unit/00_dokku-standard.bats index cb9857e399c..2c93d57c22a 100644 --- a/tests/unit/00_dokku-standard.bats +++ b/tests/unit/00_dokku-standard.bats @@ -12,6 +12,20 @@ teardown() { disable_tls_wildcard } +assert_urls() { + urls=$@ + run dokku urls $TEST_APP + echo "output: "$output + echo "status: "$status + assert_output < <(tr ' ' '\n' <<< "${urls}") +} + +build_nginx_config() { + # simulate nginx post-deploy + dokku domains:setup $TEST_APP + dokku nginx:build-config $TEST_APP +} + @test "run (with tty)" { deploy_app run /bin/bash -c "dokku run $TEST_APP ls /app/package.json" @@ -29,24 +43,29 @@ teardown() { } @test "urls (non-ssl)" { - run bash -c "dokku urls $TEST_APP | grep dokku.me" - echo "output: "$output - echo "status: "$status - assert_output "http://dokku.me" + assert_urls "http://dokku.me" + build_nginx_config + assert_urls "http://${TEST_APP}.dokku.me" + add_domain "test.dokku.me" + assert_urls "http://${TEST_APP}.dokku.me" "http://test.dokku.me" } @test "urls (app ssl)" { setup_test_tls - run bash -c "dokku urls $TEST_APP | grep dokku.me" - echo "output: "$output - echo "status: "$status - assert_output "https://dokku.me" + assert_urls "https://dokku.me" + build_nginx_config + assert_urls "https://node-js-app.dokku.me" "http://${TEST_APP}.dokku.me" + add_domain "test.dokku.me" + assert_urls "https://node-js-app.dokku.me" "http://${TEST_APP}.dokku.me" "http://test.dokku.me" } @test "urls (wildcard ssl)" { setup_test_tls_wildcard - run bash -c "dokku urls $TEST_APP | grep dokku.me" - echo "output: "$output - echo "status: "$status - assert_output "https://dokku.me" + assert_urls "https://dokku.me" + build_nginx_config + assert_urls "https://${TEST_APP}.dokku.me" + add_domain "test.dokku.me" + assert_urls "https://${TEST_APP}.dokku.me" "https://test.dokku.me" + add_domain "dokku.example.com" + assert_urls "https://${TEST_APP}.dokku.me" "https://test.dokku.me" "http://dokku.example.com" } diff --git a/tests/unit/test_helper.bash b/tests/unit/test_helper.bash index 08b05c45a43..08d16f8ae77 100644 --- a/tests/unit/test_helper.bash +++ b/tests/unit/test_helper.bash @@ -92,6 +92,10 @@ destroy_app() { echo $TEST_APP | dokku apps:destroy $TEST_APP } +add_domain() { + dokku domains:add $TEST_APP $1 +} + deploy_app() { APP_TYPE="$1"; APP_TYPE=${APP_TYPE:="nodejs-express"} TMP=$(mktemp -d -t "$TARGET.XXXXX")