Skip to content

Commit

Permalink
Fixes sticky app url in site change
Browse files Browse the repository at this point in the history
  • Loading branch information
octoberapp committed May 30, 2024
1 parent b005ac2 commit 84f3ecb
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
5 changes: 0 additions & 5 deletions src/Foundation/Bootstrap/RegisterOctober.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,6 @@ class RegisterOctober
*/
public function bootstrap(Application $app)
{
// Workaround for CLI and URL based in subdirectory
if ($app->runningInConsole()) {
$app['url']->forceRootUrl($app['config']->get('app.url'));
}

// Register singletons
$app->singleton('string', function () {
return new \October\Rain\Support\Str;
Expand Down
20 changes: 14 additions & 6 deletions src/Html/UrlServiceProvider.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
<?php namespace October\Rain\Html;

use Str;
use Config;
use Illuminate\Support\ServiceProvider;

/**
Expand All @@ -20,6 +18,10 @@ public function register()
$this->registerUrlGeneratorPolicy();
$this->registerRelativeHelper();
$this->registerPjaxCached();

$this->app['events']->listen('site.changed', function() {
$this->registerUrlGeneratorPolicy();
});
}

/**
Expand All @@ -33,14 +35,13 @@ public function register()
public function registerUrlGeneratorPolicy()
{
$provider = $this->app['url'];
$policy = Config::get('system.link_policy', 'detect');
$policy = $this->app['config']->get('system.link_policy', 'detect');
$appUrl = $this->app['config']->get('app.url');

switch (strtolower($policy)) {
case 'force':
$appUrl = Config::get('app.url');
$schema = Str::startsWith($appUrl, 'http://') ? 'http' : 'https';
$provider->forceRootUrl($appUrl);
$provider->forceScheme($schema);
$provider->forceScheme(str_starts_with($appUrl, 'http://') ? 'http' : 'https');
break;

case 'insecure':
Expand All @@ -51,6 +52,13 @@ public function registerUrlGeneratorPolicy()
$provider->forceScheme('https');
break;
}

// Workaround for October CMS installed to a subdirectory since
// Laravel won't support this use case, related issue:
// https://github.com/laravel/framework/pull/3918
if ($this->app->runningInConsole()) {
$provider->forceRootUrl($appUrl);
}
}

/**
Expand Down

0 comments on commit 84f3ecb

Please sign in to comment.