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

Merge pull request #1460 from rana01645/master

Update "fetch-share-url" to pull correct URL for HTTPS tunnels, not just HTTP
This commit is contained in:
Matt Stauffer
2023-12-20 22:39:06 -05:00
committed by GitHub
2 changed files with 24 additions and 5 deletions

View File

@@ -51,22 +51,33 @@ public function currentTunnelUrl(?string $domain = null): string
} }
/** /**
* Find the HTTP tunnel URL from the list of tunnels. * Find the HTTP/HTTPS tunnel URL from the list of tunnels.
*/ */
public function findHttpTunnelUrl(array $tunnels, string $domain): ?string public function findHttpTunnelUrl(array $tunnels, string $domain): ?string
{ {
$httpTunnel = null;
$httpsTunnel = null;
// 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 dev purposes we just desire the plain HTTP URL endpoint. // if no HTTP tunnel is found we will return the HTTPS tunnel as a fallback.
// Iterate through tunnels to find both HTTP and HTTPS tunnels
foreach ($tunnels as $tunnel) { foreach ($tunnels as $tunnel) {
if ($tunnel->proto === 'http' && strpos($tunnel->config->addr, strtolower($domain))) { if (stripos($tunnel->config->addr, $domain)) {
return $tunnel->public_url; if ($tunnel->proto === 'http') {
$httpTunnel = $tunnel->public_url;
} elseif ($tunnel->proto === 'https') {
$httpsTunnel = $tunnel->public_url;
}
} }
} }
return null; // Return HTTP tunnel if available, otherwise return HTTPS tunnel
return $httpTunnel ?? $httpsTunnel;
} }
/** /**
* Set the Ngrok auth token. * Set the Ngrok auth token.
*/ */

View File

@@ -47,10 +47,18 @@ public function test_it_matches_correct_share_tunnel()
], ],
'public_url' => 'http://right-one.ngrok.io/', 'public_url' => 'http://right-one.ngrok.io/',
], ],
(object) [
'proto' => 'https',
'config' => (object) [
'addr' => 'http://mysecuresite.test:80',
],
'public_url' => 'http://secure-right-one.ngrok.io/',
],
]; ];
$ngrok = resolve(Ngrok::class); $ngrok = resolve(Ngrok::class);
$this->assertEquals('http://right-one.ngrok.io/', $ngrok->findHttpTunnelUrl($tunnels, 'mysite')); $this->assertEquals('http://right-one.ngrok.io/', $ngrok->findHttpTunnelUrl($tunnels, 'mysite'));
$this->assertEquals('http://secure-right-one.ngrok.io/', $ngrok->findHttpTunnelUrl($tunnels, 'mysecuresite'));
} }
public function test_it_checks_against_lowercased_domain() public function test_it_checks_against_lowercased_domain()