diff --git a/app/Providers/AppServiceProvider.php b/app/Providers/AppServiceProvider.php index ba434c79e..486410a5f 100644 --- a/app/Providers/AppServiceProvider.php +++ b/app/Providers/AppServiceProvider.php @@ -45,7 +45,7 @@ public function boot(): void { $this->defineCustomIfStatements(); $this->defineGates(); - $this->forceHttps(); + $this->configureUrl(); $this->setApiRateLimit(); $this->registerNotificationChannels(); @@ -111,10 +111,12 @@ protected function defineGates(): void } /** - * Force https scheme in non-local environments. + * Configure URL generation settings. */ - protected function forceHttps(): void + protected function configureUrl(): void { + URL::useOrigin(config('app.url')); + if (! app()->environment('local') && config('app.force_https')) { URL::forceScheme('https'); } diff --git a/tests/Feature/UrlGenerationTest.php b/tests/Feature/UrlGenerationTest.php new file mode 100644 index 000000000..9f9e559c8 --- /dev/null +++ b/tests/Feature/UrlGenerationTest.php @@ -0,0 +1,57 @@ +set('app.url', 'https://myserver.com/speedtest'); + + (new AppServiceProvider(app()))->boot(); + + $url = route('getting-started'); + + expect($url)->toContain('/speedtest/'); + }); + + test('url() helper respects subpath configuration', function () { + URL::useOrigin('http://localhost'); + config()->set('app.url', 'https://myserver.com/speedtest'); + + (new AppServiceProvider(app()))->boot(); + + $url = url('/'); + + expect($url)->toContain('/speedtest'); + }); +}); + +describe('url generation without subpath', function () { + test('route() helper generates plain path when APP_URL has no subpath', function () { + URL::useOrigin('http://localhost'); + config()->set('app.url', 'https://myserver.com'); + + (new AppServiceProvider(app()))->boot(); + + $url = route('getting-started'); + + expect($url)->not->toContain('/speedtest/'); + }); + + test('url() helper works correctly without subpath', function () { + URL::useOrigin('http://localhost'); + config()->set('app.url', 'https://myserver.com'); + + (new AppServiceProvider(app()))->boot(); + + $url = url('/'); + + expect($url)->not->toContain('/speedtest'); + }); +});