Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

browsersync should default to HTTPS, fixes #19 #21

Merged
merged 5 commits into from
Nov 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
18 changes: 8 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
- [Basic usage](#basic-usage)
- [Problems](#problems)
- [Laravel-mix configuration](#laravel-mix-configuration)
- [TODO](#todo)

## Introduction

Expand All @@ -23,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
Expand All @@ -34,7 +31,12 @@ 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: <http://d9.ddev.site:3000>".
link to the browsersync proxy URL, something like `https://<project>.ddev.site:3000`.

NOTE: The browsersync'd URL is ***HTTPS***, not HTTP. ddev-router redirects traffic to HTTPS, but browsersync does not know this.

EG.
"External: <http://d9.ddev.site:3000>" => Access on **<https://d9.ddev.site:3000>**

## What does this add-on do and add?

Expand Down Expand Up @@ -103,18 +105,14 @@ 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
External: http://browsersync-demo.ddev.site:3000
---------------------------------------------------
```

- Browsersync will be running at `https://browsersync-demo.ddev.site:3000`

## TODO

- Browsersync proxy HTTPS version
- Browsersync will be running on **HTTPS** at `https://browsersync-demo.ddev.site:3000`

**Contributed and maintained by [tyler36](https://github.com/tyler36)**
3 changes: 2 additions & 1 deletion commands/web/browsersync
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 2 additions & 2 deletions docker-compose.browsersync.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 2 additions & 4 deletions tests/run-ddev-browsersync
Original file line number Diff line number Diff line change
@@ -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"
24 changes: 15 additions & 9 deletions tests/test.bats
Original file line number Diff line number Diff line change
@@ -1,36 +1,39 @@
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 "<html><head></head><body>this is a test</body>" >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}
}

@test "install from directory" {
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 http://${PROJNAME}.ddev.site:3000 | grep "this is a test"
${CURLCMD} https://${PROJNAME}.ddev.site:3000 | grep "this is a test"
}

@test "install from release" {
Expand All @@ -39,5 +42,8 @@ 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
# 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"
}