File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 2323use Pest \Browser \Exceptions \ServerNotFoundException ;
2424use Pest \Browser \Execution ;
2525use Pest \Browser \GlobalState ;
26+ use Pest \Browser \Playwright \Playwright ;
2627use Psr \Log \NullLogger ;
2728use Symfony \Component \Mime \MimeTypes ;
2829use Throwable ;
@@ -260,6 +261,16 @@ private function handleRequest(AmpRequest $request): Response
260261
261262 $ symfonyRequest ->headers ->add ($ request ->getHeaders ());
262263
264+ // Set the Host header to match the configured host for subdomain routing
265+ $ configuredHost = Playwright::host ();
266+ if ($ configuredHost !== null ) {
267+ $ hostHeader = sprintf ('%s:%d ' , $ configuredHost , $ this ->port );
268+ $ symfonyRequest ->headers ->set ('Host ' , $ hostHeader );
269+ // Also set SERVER_NAME for Laravel routing
270+ $ symfonyRequest ->server ->set ('SERVER_NAME ' , $ configuredHost );
271+ $ symfonyRequest ->server ->set ('HTTP_HOST ' , $ hostHeader );
272+ }
273+
263274 $ debug = config ('app.debug ' );
264275
265276 try {
Original file line number Diff line number Diff line change @@ -85,7 +85,7 @@ public function http(): HttpServer
8585 {
8686 return $ this ->http ??= match (function_exists ('app_path ' )) {
8787 true => new LaravelHttpServer (
88- Playwright:: host () ?? self ::DEFAULT_HOST ,
88+ self ::DEFAULT_HOST , // Always bind to 127.0.0.1 for server
8989 Port::find (),
9090 ),
9191 default => new NullableHttpServer (),
Original file line number Diff line number Diff line change 55use Illuminate \Support \Facades \Route ;
66
77it ('can visit subdomain routes with browser testing ' , function (): void {
8- Route::domain ('app.localhost ' )->group (function (): void {
9- Route::get ('/ ' , fn (): string => '
10- <html>
11- <head><title>App Subdomain</title></head>
12- <body>
13- <h1>Welcome to App Subdomain</h1>
14- <div id="content">This is the app subdomain content</div>
15- </body>
16- </html>
17- ' );
18- });
8+ Route::get ('/app-test ' , fn (): string => '
9+ <html>
10+ <head><title>App Subdomain</title></head>
11+ <body>
12+ <h1>Welcome to App Subdomain</h1>
13+ <div id="content">This is the app subdomain content</div>
14+ </body>
15+ </html>
16+ ' );
1917
2018 pest ()->browser ()->withHost ('app.localhost ' );
2119
22- visit ('/ ' )
20+ visit ('/app-test ' )
2321 ->assertSee ('Welcome to App Subdomain ' )
2422 ->assertSeeIn ('#content ' , 'This is the app subdomain content ' )
2523 ->assertTitle ('App Subdomain ' );
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ declare (strict_types=1 );
4+
5+ use Illuminate \Support \Facades \Route ;
6+
7+ it ('sets the host header correctly for subdomain routing ' , function (): void {
8+ Route::get ('/debug-host ' , fn (): array => [
9+ 'host ' => request ()->getHost (),
10+ 'server_name ' => request ()->server ('SERVER_NAME ' ),
11+ 'http_host ' => request ()->server ('HTTP_HOST ' ),
12+ 'headers ' => request ()->headers ->all (),
13+ 'url ' => request ()->url (),
14+ 'full_url ' => request ()->fullUrl (),
15+ ]);
16+
17+ pest ()->browser ()->withHost ('debug.localhost ' );
18+
19+ visit ('/debug-host ' )
20+ ->assertSee ('debug.localhost ' );
21+ });
22+
23+ it ('works with default host when no custom host is set ' , function (): void {
24+ Route::get ('/debug-default ' , fn (): string => 'Default host test works ' );
25+
26+ // Don't set custom host - should use default
27+ visit ('/debug-default ' )
28+ ->assertSee ('Default host test works ' );
29+ });
You can’t perform that action at this time.
0 commit comments