Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions app/Providers/AppServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public function boot(): void
{
$this->defineCustomIfStatements();
$this->defineGates();
$this->forceHttps();
$this->configureUrl();
$this->setApiRateLimit();
$this->registerNotificationChannels();

Expand Down Expand Up @@ -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');
}
Expand Down
57 changes: 57 additions & 0 deletions tests/Feature/UrlGenerationTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?php

use App\Providers\AppServiceProvider;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\URL;

beforeEach(function () {
Cache::flush();
});

describe('url generation with subpath', function () {
test('route() helper generates URLs with subpath', function () {
URL::useOrigin('http://localhost');
config()->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');
});
});