Skip to content

Commit

Permalink
Fix share command
Browse files Browse the repository at this point in the history
  • Loading branch information
cretueusebiu committed Dec 30, 2016
1 parent 7c9c163 commit c5e24c5
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 47 deletions.
4 changes: 4 additions & 0 deletions cli/includes/helpers.php
Expand Up @@ -3,6 +3,10 @@
use Illuminate\Container\Container;
use Symfony\Component\Process\Process;

if (!isset($_SERVER['HOME'])) {
$_SERVER['HOME'] = $_SERVER['USERPROFILE'];
}

/**
* Define the ~/.valet path as a constant.
*/
Expand Down
5 changes: 4 additions & 1 deletion cli/valet.php
Expand Up @@ -187,7 +187,10 @@
* Generate a publicly accessible URL for your project.
*/
$app->command('share', function () {
warning("It looks like you are running `cli/valet.php` directly, please use the `valet` script in the project root instead.");
$host = basename(getcwd());
$domain = Configuration::read()['domain'];

passthru("start ".__DIR__."/../bin/ngrok http $host.$domain:80 -host-header=rewrite");
})->descriptions('Generate a publicly accessible URL for your project');

/**
Expand Down
52 changes: 6 additions & 46 deletions valet
@@ -1,48 +1,8 @@
#!/usr/bin/env bash
#!/usr/bin/env php
<?php

SOURCE="${BASH_SOURCE[0]}"
if (!isset($_SERVER['HOME'])) {
$_SERVER['HOME'] = $_SERVER['USERPROFILE'];
}

# If the current source is a symbolic link, we need to resolve it to an
# actual directory name. We'll use PHP to do this easier than we can
# do it in pure Bash. So, we'll call into PHP CLI here to resolve.
if [[ -L $SOURCE ]]
then
DIR=$(php -r "echo dirname(realpath('$SOURCE'));")
else
DIR="$( cd "$( dirname "$SOURCE" )" && pwd )"
fi

# If we are in the global Composer "bin" directory, we need to bump our
# current directory up two, so that we will correctly proxy into the
# Valet CLI script which is written in PHP. Will use PHP to do it.
if [ ! -f "$DIR/cli/valet.php" ]
then
DIR=$(php -r "echo realpath('$DIR/../laravel/valet');")
fi

# If the command is the "share" command we will need to resolve out any
# symbolic links for the site. Before starting Ngrok, we will fire a
# process to retrieve the live Ngrok tunnel URL in the background.
if [[ "$1" = "share" ]]
then
HOST="${PWD##*/}"
DOMAIN=$(php "$DIR/cli/valet.php" domain)

for linkname in ~/.valet/Sites/*; do
if [[ "$(readlink $linkname)" = "$PWD" ]]
then
HOST="${linkname##*/}"
fi
done

# Fetch Ngrok URL In Background...
bash "$DIR/cli/scripts/fetch-share-url.sh" &
"$DIR/bin/ngrok" http "$HOST.$DOMAIN:80" -host-header=rewrite ${*:2}
exit

# Finally, for every other command we will just proxy into the PHP tool
# and let it handle the request. These are commands which can be run
# without sudo and don't require taking over terminals like Ngrok.
else
php "$DIR/cli/valet.php" "$@"
fi
require __DIR__.'/cli/valet.php';

0 comments on commit c5e24c5

Please sign in to comment.