diff --git a/src/Drivers/LaravelHttpServer.php b/src/Drivers/LaravelHttpServer.php index 7edf0a5e..97ae5fdb 100644 --- a/src/Drivers/LaravelHttpServer.php +++ b/src/Drivers/LaravelHttpServer.php @@ -23,6 +23,7 @@ use Pest\Browser\Exceptions\ServerNotFoundException; use Pest\Browser\Execution; use Pest\Browser\GlobalState; +use Pest\Browser\Playwright\Playwright; use Psr\Log\NullLogger; use Symfony\Component\Mime\MimeTypes; use Throwable; @@ -260,6 +261,16 @@ private function handleRequest(AmpRequest $request): Response $symfonyRequest->headers->add($request->getHeaders()); + // Set the Host header to match the configured host for subdomain routing + $configuredHost = Playwright::host(); + if ($configuredHost !== null) { + $hostHeader = sprintf('%s:%d', $configuredHost, $this->port); + $symfonyRequest->headers->set('Host', $hostHeader); + // Also set SERVER_NAME for Laravel routing + $symfonyRequest->server->set('SERVER_NAME', $configuredHost); + $symfonyRequest->server->set('HTTP_HOST', $hostHeader); + } + $debug = config('app.debug'); try { diff --git a/src/ServerManager.php b/src/ServerManager.php index 6fbe9438..4e406fd9 100644 --- a/src/ServerManager.php +++ b/src/ServerManager.php @@ -85,7 +85,7 @@ public function http(): HttpServer { return $this->http ??= match (function_exists('app_path')) { true => new LaravelHttpServer( - Playwright::host() ?? self::DEFAULT_HOST, + self::DEFAULT_HOST, // Always bind to 127.0.0.1 for server Port::find(), ), default => new NullableHttpServer(), diff --git a/tests/Browser/Visit/SubdomainTest.php b/tests/Browser/Visit/SubdomainTest.php index fd466eb7..702157b6 100644 --- a/tests/Browser/Visit/SubdomainTest.php +++ b/tests/Browser/Visit/SubdomainTest.php @@ -4,28 +4,26 @@ use Illuminate\Support\Facades\Route; -it('can visit subdomain routes with browser testing', function (): void { - Route::domain('app.localhost')->group(function (): void { - Route::get('/', fn (): string => ' - -