From ef8b415b23fb28602f5e26458850e14ebaea7694 Mon Sep 17 00:00:00 2001 From: tyler36 <7234392+tyler36@users.noreply.github.com> Date: Fri, 11 Nov 2022 00:17:58 +0000 Subject: [PATCH 1/5] browsersync should default to HTTPS --- README.md | 7 +------ docker-compose.browsersync.yaml | 4 ++-- 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 3988282..ad7d920 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,6 @@ - [Basic usage](#basic-usage) - [Problems](#problems) - [Laravel-mix configuration](#laravel-mix-configuration) -- [TODO](#todo) ## Introduction @@ -103,7 +102,7 @@ mix.js('resources/js/app.js', 'public/js') ```shell ddev exec npm run watch ... -[Browsersync] Proxying: http://browsersync-demo.ddev.site +[Browsersync] Proxying: http://localhost:3000 [Browsersync] Access URLs: --------------------------------------------------- Local: http://localhost:3000 @@ -113,8 +112,4 @@ ddev exec npm run watch - Browsersync will be running at `https://browsersync-demo.ddev.site:3000` -## TODO - -- Browsersync proxy HTTPS version - **Contributed and maintained by [tyler36](https://github.com/tyler36)** diff --git a/docker-compose.browsersync.yaml b/docker-compose.browsersync.yaml index 4e94adf..f0e825d 100644 --- a/docker-compose.browsersync.yaml +++ b/docker-compose.browsersync.yaml @@ -6,5 +6,5 @@ services: expose: - '3000' environment: - - HTTP_EXPOSE=${DDEV_ROUTER_HTTP_PORT}:80,${DDEV_MAILHOG_PORT}:8025,3000:3000 - - HTTPS_EXPOSE=${DDEV_ROUTER_HTTPS_PORT}:80,${DDEV_MAILHOG_HTTPS_PORT}:8025 + - HTTP_EXPOSE=${DDEV_ROUTER_HTTP_PORT}:80,${DDEV_MAILHOG_PORT}:8025,3001:3000 + - HTTPS_EXPOSE=${DDEV_ROUTER_HTTPS_PORT}:80,${DDEV_MAILHOG_HTTPS_PORT}:8025,3000:3000 From 6f97c65fe8a5cb7d1f4a8462d683a9a042511b48 Mon Sep 17 00:00:00 2001 From: tyler36 <7234392+tyler36@users.noreply.github.com> Date: Fri, 11 Nov 2022 00:17:58 +0000 Subject: [PATCH 2/5] update test to verify HTTPS --- tests/test.bats | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test.bats b/tests/test.bats index 75f8e2f..6327408 100644 --- a/tests/test.bats +++ b/tests/test.bats @@ -30,7 +30,7 @@ teardown() { ddev restart ./run-ddev-browsersync & sleep 5 - curl -s --fail http://${PROJNAME}.ddev.site:3000 | grep "this is a test" + curl -s --fail https://${PROJNAME}.ddev.site:3000 | grep "this is a test" } @test "install from release" { From a3e395d5ab44061cd10a0bd49ca88b606986d070 Mon Sep 17 00:00:00 2001 From: tyler36 <7234392+tyler36@users.noreply.github.com> Date: Fri, 11 Nov 2022 00:17:58 +0000 Subject: [PATCH 3/5] additional notes about HTTPS in readme --- README.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index ad7d920..2f824eb 100644 --- a/README.md +++ b/README.md @@ -35,6 +35,11 @@ ddev browsersync The new `ddev browsersync` global command runs browsersync inside the web container and provides a link ("External") to the browsersync-update URL. Use the URL in the output that says something like "External: ". +NOTE: The browsersync'd URL is ***HTTPS***, not HTTP. ddev-router redirects traffic to HTTPS, but browsersync does not know this. + +EG. +"External: " => Access on **** + ## What does this add-on do and add? 1. Checks to make sure the DDEV version is adequate. @@ -110,6 +115,6 @@ ddev exec npm run watch --------------------------------------------------- ``` -- Browsersync will be running at `https://browsersync-demo.ddev.site:3000` +- Browsersync will be running on **HTTPS** at `https://browsersync-demo.ddev.site:3000` **Contributed and maintained by [tyler36](https://github.com/tyler36)** From 67b473d98c8f61898d76f19ebcb7c2b8391db769 Mon Sep 17 00:00:00 2001 From: tyler36 <7234392+tyler36@users.noreply.github.com> Date: Fri, 11 Nov 2022 00:47:04 +0000 Subject: [PATCH 4/5] replace test comment --- tests/test.bats | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/test.bats b/tests/test.bats index 6327408..272fdea 100644 --- a/tests/test.bats +++ b/tests/test.bats @@ -39,5 +39,7 @@ teardown() { echo "# ddev get drud/ddev-browsersync with project ${PROJNAME} in ${TESTDIR} ($(pwd))" >&3 ddev get drud/ddev-browsersync ddev restart - # ddev exec "curl -s elasticsearch:9200" | grep "${PROJNAME}-elasticsearch" + # ./run-ddev-browsersync & + # sleep 5 + # curl -s --fail https://${PROJNAME}.ddev.site:3000 | grep "this is a test" } From 12d7b150adf00adaa67c5c7d90c5741cb59c2972 Mon Sep 17 00:00:00 2001 From: Randy Fay Date: Tue, 29 Nov 2022 17:09:54 -0700 Subject: [PATCH 5/5] https-support PR: Make it report the right URL, improve tests (#31) * Improve output of ddev browsersync to show https URL * Update tests and github setup to make work with https * Do mkcert -install so we can trust certs --- .github/workflows/tests.yml | 10 ++++++++-- README.md | 4 +--- commands/web/browsersync | 3 ++- tests/run-ddev-browsersync | 6 ++---- tests/test.bats | 26 +++++++++++++++----------- 5 files changed, 28 insertions(+), 21 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 24ffd71..adcf9ce 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -37,11 +37,17 @@ jobs: steps: - uses: actions/checkout@v2 - - run: echo "/home/linuxbrew/.linuxbrew/bin:/home/linuxbrew/.linuxbrew/sbin" >> $GITHUB_PATH + - name: Set up Homebrew + id: set-up-homebrew + uses: Homebrew/actions/setup-homebrew@master + - name: Environment setup run: | - brew install bats-core + brew install bats-core mkcert sudo apt-get update >/dev/null && sudo apt-get install -y expect >/dev/null + # Without this .curlrc some linux images don't respect mkcert certs + echo "capath=/etc/ssl/certs/" >>~/.curlrc + mkcert -install - name: Use ddev stable if: matrix.ddev_version == 'stable' diff --git a/README.md b/README.md index 2f824eb..0f02323 100644 --- a/README.md +++ b/README.md @@ -22,8 +22,6 @@ This add-on allows you to run [Browsersync](https://browsersync.io/) through the ## Getting Started -This add-on requires DDEV v1.19.3 or higher. - - Install the DDEV browsersync add-on: ```shell @@ -33,7 +31,7 @@ ddev browsersync ``` The new `ddev browsersync` global command runs browsersync inside the web container and provides a -link ("External") to the browsersync-update URL. Use the URL in the output that says something like "External: ". +link to the browsersync proxy URL, something like `https://.ddev.site:3000`. NOTE: The browsersync'd URL is ***HTTPS***, not HTTP. ddev-router redirects traffic to HTTPS, but browsersync does not know this. diff --git a/commands/web/browsersync b/commands/web/browsersync index f2fed64..ed9dd74 100755 --- a/commands/web/browsersync +++ b/commands/web/browsersync @@ -6,4 +6,5 @@ ## Example: "ddev browsersync" ## ExecRaw: true -browser-sync start -c .ddev/browser-sync.js +echo "Proxying browsersync on ${DDEV_PRIMARY_URL}:3000" +browser-sync start -c /var/www/html/.ddev/browser-sync.js >/dev/null diff --git a/tests/run-ddev-browsersync b/tests/run-ddev-browsersync index f40f3d4..3caf1b9 100755 --- a/tests/run-ddev-browsersync +++ b/tests/run-ddev-browsersync @@ -1,9 +1,7 @@ #!/usr/bin/expect -f set PROJNAME $::env(PROJNAME) -set timeout -1 +set timeout 10 spawn ddev browsersync -expect "http://${PROJNAME}.ddev.site:3000" - -expect "wait forever" +expect "https?://${PROJNAME}.ddev.site:3000" diff --git a/tests/test.bats b/tests/test.bats index 272fdea..2c2700e 100644 --- a/tests/test.bats +++ b/tests/test.bats @@ -1,24 +1,27 @@ setup() { set -eu -o pipefail # Fail early if old ddev is installed - ddev debug capabilities | grep multiple-dockerfiles || exit 3 + ddev debug capabilities | grep multiple-dockerfiles >/dev/null || exit 3 export DIR="$( cd "$( dirname "$BATS_TEST_FILENAME" )" >/dev/null 2>&1 && pwd )/.." export TESTDIR=~/tmp/testbrowsersync - mkdir -p $TESTDIR + mkdir -p "${TESTDIR}" export PROJNAME=ddev-browsersync export DDEV_NON_INTERACTIVE=true - ddev delete -Oy ${PROJNAME} || true + ddev delete -Oy ${PROJNAME} >/dev/null || true cp tests/run-ddev-browsersync "${TESTDIR}" cd "${TESTDIR}" - ddev config --project-name=${PROJNAME} + ddev config --project-name=${PROJNAME} >/dev/null echo "this is a test" >index.html ddev start -y + CURLCMD="curl -s --fail" + # I can't currently get curl to trust mkcert CA on macOS + if [[ "$OSTYPE" == "darwin"* ]]; then CURLCMD="curl -s -k --fail"; fi } teardown() { set -eu -o pipefail cd ${TESTDIR} || ( printf "unable to cd to ${TESTDIR}\n" && exit 1 ) - ddev delete -Oy ${PROJNAME} + ddev delete -Oy ${PROJNAME} >/dev/null [ "${TESTDIR}" != "" ] && rm -rf ${TESTDIR} } @@ -26,11 +29,11 @@ teardown() { set -eu -o pipefail cd ${TESTDIR} echo "# ddev get ${DIR} with project ${PROJNAME} in ${TESTDIR} ($(pwd))" >&3 - ddev get ${DIR} - ddev restart + ddev get ${DIR} >/dev/null + ddev restart >/dev/null ./run-ddev-browsersync & sleep 5 - curl -s --fail https://${PROJNAME}.ddev.site:3000 | grep "this is a test" + ${CURLCMD} https://${PROJNAME}.ddev.site:3000 | grep "this is a test" } @test "install from release" { @@ -39,7 +42,8 @@ teardown() { echo "# ddev get drud/ddev-browsersync with project ${PROJNAME} in ${TESTDIR} ($(pwd))" >&3 ddev get drud/ddev-browsersync ddev restart - # ./run-ddev-browsersync & - # sleep 5 - # curl -s --fail https://${PROJNAME}.ddev.site:3000 | grep "this is a test" + ./run-ddev-browsersync & + sleep 5 + # After https PR goes in, this should be changed to just https + (${CURLCMD} https://${PROJNAME}.ddev.site:3000 || ${CURLCMD} http://${PROJNAME}.ddev.site:3000) | grep "this is a test" }