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

Merge pull request #864 from drbyte/ngrok-multiple

Fix auto-detection amongst multiple ngrok processes
This commit is contained in:
Matt Stauffer
2019-12-05 15:13:43 -05:00
committed by GitHub
2 changed files with 7 additions and 7 deletions

View File

@@ -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;
}
}

View File

@@ -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');
/**