2021-06-26 23:23:15 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace BookStack\Http;
|
2019-08-04 21:26:39 +08:00
|
|
|
|
|
|
|
use Illuminate\Http\Request as LaravelRequest;
|
|
|
|
|
|
|
|
class Request extends LaravelRequest
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Override the default request methods to get the scheme and host
|
2022-04-03 00:14:37 +08:00
|
|
|
* to directly use the custom APP_URL, if set.
|
2019-08-04 21:26:39 +08:00
|
|
|
*/
|
2023-02-07 04:00:44 +08:00
|
|
|
public function getSchemeAndHttpHost(): string
|
2019-08-04 21:26:39 +08:00
|
|
|
{
|
2022-04-03 00:14:37 +08:00
|
|
|
$appUrl = config('app.url', null);
|
2019-08-04 21:26:39 +08:00
|
|
|
|
2022-04-03 00:14:37 +08:00
|
|
|
if ($appUrl) {
|
|
|
|
return implode('/', array_slice(explode('/', $appUrl), 0, 3));
|
2019-08-04 21:26:39 +08:00
|
|
|
}
|
|
|
|
|
2022-04-03 00:14:37 +08:00
|
|
|
return parent::getSchemeAndHttpHost();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Override the default request methods to get the base URL
|
|
|
|
* to directly use the custom APP_URL, if set.
|
2022-04-13 19:46:19 +08:00
|
|
|
* The base URL never ends with a / but should start with one if not empty.
|
2022-04-03 00:14:37 +08:00
|
|
|
*/
|
2023-02-07 04:00:44 +08:00
|
|
|
public function getBaseUrl(): string
|
2022-04-03 00:14:37 +08:00
|
|
|
{
|
|
|
|
$appUrl = config('app.url', null);
|
|
|
|
|
|
|
|
if ($appUrl) {
|
2022-05-05 03:08:22 +08:00
|
|
|
$parsedBaseUrl = rtrim(implode('/', array_slice(explode('/', $appUrl), 3)), '/');
|
2022-05-05 04:19:46 +08:00
|
|
|
|
2022-05-05 03:08:22 +08:00
|
|
|
return empty($parsedBaseUrl) ? '' : ('/' . $parsedBaseUrl);
|
2022-04-03 00:14:37 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return parent::getBaseUrl();
|
2019-08-04 21:26:39 +08:00
|
|
|
}
|
2019-09-16 01:29:51 +08:00
|
|
|
}
|