diff --git a/bin/dev b/bin/dev index d01747dd3..21ef0eeeb 100755 --- a/bin/dev +++ b/bin/dev @@ -1,8 +1,13 @@ #!/usr/bin/env sh -bin/rails runner - </dev/null 2>&1; then + echo "Error: tailscale not found" >&2 + exit 1 + fi + + TS_STATUS=$(tailscale status --self --json 2>&1) + if [ $? -ne 0 ]; then + echo "Error: tailscale not logged in" >&2 + exit 1 + fi + + TS_HOSTNAME=$(echo "$TS_STATUS" | jq -r '.Self.DNSName | rtrimstr(".")') + TS_PORT="4$PORT" + + stop_tailscale() { tailscale serve --https=$TS_PORT off >/dev/null 2>&1; } + trap stop_tailscale EXIT INT TERM + + tailscale serve --bg --https=$TS_PORT "http://fizzy.localhost:$PORT" >/dev/null 2>&1 + echo "Login with david@example.com to: https://$TS_HOSTNAME:$TS_PORT/" +else + echo "Login with david@example.com to: http://fizzy.localhost:$PORT/" +fi + +./bin/rails server -p $PORT