From 8b2e23579228a06a5973075c3a5c9f0ffc3b82c5 Mon Sep 17 00:00:00 2001 From: Mayank Chhabra Date: Sun, 6 Sep 2020 09:21:06 +0530 Subject: [PATCH] Export a list of device hosts for CORS whitelist (#219) --- docker-compose.yml | 4 ++-- scripts/start | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 3da9520..a03a242 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -97,7 +97,7 @@ services: JWT_PRIVATE_KEY_FILE: "/jwt-private-key/jwt.key" JWT_EXPIRATION: "3600" DOCKER_COMPOSE_DIRECTORY: $PWD - DEVICE_HOST: ${DEVICE_HOST:-http://umbrel.local} + DEVICE_HOSTS: ${DEVICE_HOSTS:-"http://umbrel.local"} MIDDLEWARE_API_URL: "http://10.11.2.2" UMBREL_SEED_FILE: "/db/umbrel-seed/seed" UMBREL_DASHBOARD_HIDDEN_SERVICE_FILE: "/var/lib/tor/web/hostname" @@ -134,7 +134,7 @@ services: LND_NETWORK: $BITCOIN_NETWORK LND_HOST: "10.11.1.2" JWT_PUBLIC_KEY_FILE: "/jwt-public-key/jwt.pem" - DEVICE_HOST: ${DEVICE_HOST:-http://umbrel.local} + DEVICE_HOSTS: ${DEVICE_HOSTS:-"http://umbrel.local"} networks: net: ipv4_address: 10.11.2.2 diff --git a/scripts/start b/scripts/start index 7c644f1..9024816 100755 --- a/scripts/start +++ b/scripts/start @@ -49,9 +49,17 @@ echo echo "Setting environment variables..." echo + +# Whitelist device IP, hostname and hidden service for CORS DEVICE_IP="$(hostname -I | cut -d ' ' -f 1)" DEVICE_HOSTNAME="$(hostname)" -export DEVICE_HOST="http://"${DEVICE_IP:-"$DEVICE_HOSTNAME".local}"" +DEVICE_HOSTS="http://${DEVICE_IP},http://${DEVICE_HOSTNAME}.local,https://${DEVICE_HOSTNAME}.local,http://${DEVICE_HOSTNAME},https://${DEVICE_HOSTNAME}" +if [[ -f "${UMBREL_ROOT}/tor/data/web/hostname" ]]; then + hidden_service_url=$(cat "${UMBREL_ROOT}/tor/data/web/hostname") + DEVICE_HOSTS="${DEVICE_HOSTS},http://${hidden_service_url}" +fi +export DEVICE_HOSTS=$DEVICE_HOSTS + # Increase default Docker and Compose timeouts to 240s # as bitcoin can take a long while to respond export DOCKER_CLIENT_TIMEOUT=240 @@ -78,4 +86,6 @@ docker-compose up --detach --build --remove-orphans echo echo "Umbrel is now accessible at" -echo " $DEVICE_HOST" +echo " http://${DEVICE_HOSTNAME}.local" +echo " http://${DEVICE_IP}" +[[ ! -z "${hidden_service_url:-}" ]] && echo " http://${hidden_service_url}" \ No newline at end of file