diff --git a/cli/Valet/Ngrok.php b/cli/Valet/Ngrok.php index 1b393cc1a..7f2ff9b0e 100644 --- a/cli/Valet/Ngrok.php +++ b/cli/Valet/Ngrok.php @@ -14,16 +14,16 @@ class Ngrok * * @return string */ - function currentTunnelUrl() + function currentTunnelUrl($domain = null) { - return retry(20, function () { + return retry(20, function () use ($domain) { $body = Request::get($this->tunnelsEndpoint)->send()->body; // If there are active tunnels on the Ngrok instance we will spin through them and // find the one responding on HTTP. Each tunnel has an HTTP and a HTTPS address // but for local testing purposes we just desire the plain HTTP URL endpoint. if (isset($body->tunnels) && count($body->tunnels) > 0) { - return $this->findHttpTunnelUrl($body->tunnels); + return $this->findHttpTunnelUrl($body->tunnels, $domain); } else { throw new DomainException("Tunnel not established."); } @@ -36,10 +36,10 @@ function currentTunnelUrl() * @param array $tunnels * @return string|null */ - function findHttpTunnelUrl($tunnels) + function findHttpTunnelUrl($tunnels, $domain) { foreach ($tunnels as $tunnel) { - if ($tunnel->proto === 'http') { + if ($tunnel->proto === 'http' && strpos($tunnel->config->addr, $domain) ) { return $tunnel->public_url; } } diff --git a/cli/valet.php b/cli/valet.php index 146a475fc..5f7d123f8 100755 --- a/cli/valet.php +++ b/cli/valet.php @@ -226,8 +226,8 @@ /** * Echo the currently tunneled URL. */ - $app->command('fetch-share-url', function () { - output(Ngrok::currentTunnelUrl()); + $app->command('fetch-share-url [domain]', function ($domain = null) { + output(Ngrok::currentTunnelUrl($domain ?: Site::host(getcwd()).'.'.Configuration::read()['tld'])); })->descriptions('Get the URL to the current Ngrok tunnel'); /**