X-Git-Url: http://source.bookstackapp.com/bookstack/blobdiff_plain/421dd93ffd59bbe881df1f7fa86066f7f353b596..refs/pull/5280/head:/app/Http/Request.php diff --git a/app/Http/Request.php b/app/Http/Request.php index bd2761a0b..c2d430279 100644 --- a/app/Http/Request.php +++ b/app/Http/Request.php @@ -1,26 +1,41 @@ -getScheme().'://'.$this->getHttpHost(); + if ($appUrl) { + return implode('/', array_slice(explode('/', $appUrl), 0, 3)); } - return $base; + return parent::getSchemeAndHttpHost(); } -} \ No newline at end of file + /** + * 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(); + } +}