diff --git a/server.php b/server.php index 84a07f7..6cc6257 100644 --- a/server.php +++ b/server.php @@ -26,7 +26,7 @@ if (Server::hostIsIpAddress($_SERVER['HTTP_HOST'])) { $uriForIpAddressExtraction = ltrim($_SERVER['REQUEST_URI'], '/'); - if ($host = Server::valetSiteFromIpAddressUri($uriForIpAddressExtraction, $valetConfig['tld'])) { + if ($host = Server::valetSiteFromIpAddressUri($uriForIpAddressExtraction, $valetConfig['domain'])) { $_SERVER['HTTP_HOST'] = $host; $_SERVER['REQUEST_URI'] = str_replace($host, '', $uriForIpAddressExtraction); } diff --git a/tests/Unit/ServerTest.php b/tests/Unit/ServerTest.php index 4425260..1e241dc 100644 --- a/tests/Unit/ServerTest.php +++ b/tests/Unit/ServerTest.php @@ -95,4 +95,30 @@ public function it_does_not_treat_a_sibling_prefix_dir_as_inside(): void @rmdir($sibling); } } + + /** + * @test + */ + public function it_extracts_the_valet_site_from_an_ip_address_uri(): void + { + // Mirrors the LAN/IP-access flow: REQUEST_URI is "domain.test/auth/login" + // (leading slash already trimmed) and the TLD comes from config['domain']. + $this->assertSame( + 'my-site.test', + Server::valetSiteFromIpAddressUri('my-site.test/auth/login', 'test') + ); + $this->assertSame( + 'my-site.test', + Server::valetSiteFromIpAddressUri('my-site.test', 'test') + ); + } + + /** + * @test + */ + public function it_returns_null_when_the_ip_address_uri_has_no_matching_tld(): void + { + $this->assertNull(Server::valetSiteFromIpAddressUri('my-site.dev/auth', 'test')); + $this->assertNull(Server::valetSiteFromIpAddressUri('', 'test')); + } }