1
0
mirror of https://github.com/BookStackApp/BookStack.git synced 2025-07-30 04:23:11 +03:00

Merge pull request #3364 from BookStackApp/app_url_requests

Updated custom request overrides to better match original intent
This commit is contained in:
Dan Brown
2022-04-24 14:52:38 +01:00
committed by GitHub
3 changed files with 61 additions and 30 deletions

View File

@ -8,20 +8,36 @@ class Request extends LaravelRequest
{
/**
* Override the default request methods to get the scheme and host
* to set the custom APP_URL, if set.
* to directly use the custom APP_URL, if set.
*
* @return \Illuminate\Config\Repository|mixed|string
* @return string
*/
public function getSchemeAndHttpHost()
{
$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.
*
* @return string
*/
public function getBaseUrl()
{
$appUrl = config('app.url', null);
if ($appUrl) {
return '/' . rtrim(implode('/', array_slice(explode('/', $appUrl), 3)), '/');
}
return parent::getBaseUrl();
}
}