1
0
mirror of https://github.com/laravel/valet.git synced 2026-02-05 00:20:08 +01:00

Allow valet share to support multiple domains from same app

This PR allows passing a specific domain name to `valet share` in order to have the app be served for that domain.
Now how it works is this:
- (NEW) if a domain name is passed, it checks whether it matches a link (which would be required for multiple domains served by same app project), and uses that
- if a domain name is NOT passed, it looks up any links for current directory, and uses the first found link
- else falls back to current project foldername

It also still allows passing through custom ngrok parameters if desired (ref: #112), as either the 2nd parameter (no domain name passed) or (NEW) 3rd parameter

Fixes #537
This commit is contained in:
Chris Brown
2019-12-06 18:49:49 -05:00
parent 3b302b7593
commit 998e4c32df
2 changed files with 32 additions and 12 deletions

View File

@@ -2,4 +2,4 @@
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
php $DIR/../valet.php fetch-share-url | pbcopy php $DIR/../valet.php fetch-share-url $1 | pbcopy

42
valet
View File

@@ -31,18 +31,38 @@ fi
# process to retrieve the live Ngrok tunnel URL in the background. # process to retrieve the live Ngrok tunnel URL in the background.
if [[ "$1" = "share" ]] if [[ "$1" = "share" ]]
then then
# check for parameters to passthru to ngrok (they start with '-' or '--')
PARAMS=${3:-$2}
if [[ ${PARAMS:0:1} != '-' ]]; then
PARAMS=''
fi
HOST="${PWD##*/}" HOST="${PWD##*/}"
# check for custom domain passed through to the share command ($2 w/o '-' prefix)
if [[ ${2:0:1} != '-' ]]; then
# if not blank and is a link or is the cwd use it
if [[ ! -z $2 && (-L ~/.config/valet/Sites/$2 || $2 == $HOST) ]]; then
HOST=$2
CLIHOST=$2
fi
fi
# if no custom domain passed then check if there's a linked site for cwd
if [[ -z $CLIHOST ]]; then
# find the first linked site for the current dir, if one exists
for linkname in ~/.config/valet/Sites/*; do
if [[ "$(readlink $linkname)" = "$PWD" ]]
then
HOST="${linkname##*/}"
break
fi
done
fi
TLD=$(php "$DIR/cli/valet.php" tld) TLD=$(php "$DIR/cli/valet.php" tld)
for linkname in ~/.config/valet/Sites/*; do # Decide the correct PORT: uses 60 for secure, else 80
if [[ "$(readlink $linkname)" = "$PWD" ]]
then
HOST="${linkname##*/}"
fi
done
# Decide the correct PORT to use according if the site has a secure
# config or not.
if grep --quiet --no-messages 443 ~/.config/valet/Nginx/$HOST* if grep --quiet --no-messages 443 ~/.config/valet/Nginx/$HOST*
then then
PORT=60 PORT=60
@@ -51,8 +71,8 @@ then
fi fi
# Fetch Ngrok URL In Background... # Fetch Ngrok URL In Background...
bash "$DIR/cli/scripts/fetch-share-url.sh" & bash "$DIR/cli/scripts/fetch-share-url.sh" "$HOST" &
sudo -u "$(logname)" "$DIR/bin/ngrok" http "$HOST.$TLD:$PORT" -host-header=rewrite ${*:2} sudo -u "$(logname)" "$DIR/bin/ngrok" http "$HOST.$TLD:$PORT" -host-header=rewrite $PARAMS
exit exit
# Finally, for every other command we will just proxy into the PHP tool # Finally, for every other command we will just proxy into the PHP tool