mirror of
https://github.com/laravel/valet.git
synced 2026-02-07 09:10:03 +01:00
Fix auto-detection amongst multiple ngrok processes
Ngrok Pro plans allow multiple processes, which means you could be serving several sites simultaneously. This PR allows Valet to correctly identify amongst the active ngrok process URLs. Fixes #145
This commit is contained in:
@@ -14,16 +14,16 @@ class Ngrok
|
|||||||
*
|
*
|
||||||
* @return string
|
* @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;
|
$body = Request::get($this->tunnelsEndpoint)->send()->body;
|
||||||
|
|
||||||
// If there are active tunnels on the Ngrok instance we will spin through them and
|
// 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
|
// 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.
|
// but for local testing purposes we just desire the plain HTTP URL endpoint.
|
||||||
if (isset($body->tunnels) && count($body->tunnels) > 0) {
|
if (isset($body->tunnels) && count($body->tunnels) > 0) {
|
||||||
return $this->findHttpTunnelUrl($body->tunnels);
|
return $this->findHttpTunnelUrl($body->tunnels, $domain);
|
||||||
} else {
|
} else {
|
||||||
throw new DomainException("Tunnel not established.");
|
throw new DomainException("Tunnel not established.");
|
||||||
}
|
}
|
||||||
@@ -36,10 +36,10 @@ function currentTunnelUrl()
|
|||||||
* @param array $tunnels
|
* @param array $tunnels
|
||||||
* @return string|null
|
* @return string|null
|
||||||
*/
|
*/
|
||||||
function findHttpTunnelUrl($tunnels)
|
function findHttpTunnelUrl($tunnels, $domain)
|
||||||
{
|
{
|
||||||
foreach ($tunnels as $tunnel) {
|
foreach ($tunnels as $tunnel) {
|
||||||
if ($tunnel->proto === 'http') {
|
if ($tunnel->proto === 'http' && strpos($tunnel->config->addr, $domain) ) {
|
||||||
return $tunnel->public_url;
|
return $tunnel->public_url;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -226,8 +226,8 @@
|
|||||||
/**
|
/**
|
||||||
* Echo the currently tunneled URL.
|
* Echo the currently tunneled URL.
|
||||||
*/
|
*/
|
||||||
$app->command('fetch-share-url', function () {
|
$app->command('fetch-share-url [domain]', function ($domain = null) {
|
||||||
output(Ngrok::currentTunnelUrl());
|
output(Ngrok::currentTunnelUrl($domain ?: Site::host(getcwd()).'.'.Configuration::read()['tld']));
|
||||||
})->descriptions('Get the URL to the current Ngrok tunnel');
|
})->descriptions('Get the URL to the current Ngrok tunnel');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user