X-Git-Url: http://source.bookstackapp.com/bookstack/blobdiff_plain/0155525945bb030ae2265279dca8014c8cdcb2af..refs/pull/5280/head:/app/Http/Request.php diff --git a/app/Http/Request.php b/app/Http/Request.php index c5b38f1c1..c2d430279 100644 --- a/app/Http/Request.php +++ b/app/Http/Request.php @@ -8,20 +8,34 @@ class Request extends LaravelRequest { /** * Override the default request methods to get the scheme and host - * to set the custom APP_URL, if set. - * - * @return \Illuminate\Config\Repository|mixed|string + * to directly use the custom APP_URL, if set. */ - public function getSchemeAndHttpHost() + public function getSchemeAndHttpHost(): string { - $base = config('app.url', null); + $appUrl = config('app.url', null); - if ($base) { - $base = trim($base, '/'); - } else { - $base = $this->getScheme() . '://' . $this->getHttpHost(); + if ($appUrl) { + return implode('/', array_slice(explode('/', $appUrl), 0, 3)); } - return $base; + return parent::getSchemeAndHttpHost(); + } + + /** + * Override the default request methods to get the base URL + * to directly use the custom APP_URL, if set. + * The base URL never ends with a / but should start with one if not empty. + */ + public function getBaseUrl(): string + { + $appUrl = config('app.url', null); + + if ($appUrl) { + $parsedBaseUrl = rtrim(implode('/', array_slice(explode('/', $appUrl), 3)), '/'); + + return empty($parsedBaseUrl) ? '' : ('/' . $parsedBaseUrl); + } + + return parent::getBaseUrl(); } }