]> BookStack Code Mirror - bookstack/commitdiff
Updated custom request overrides to better match original intent
authorDan Brown <redacted>
Sat, 2 Apr 2022 16:14:37 +0000 (17:14 +0100)
committerDan Brown <redacted>
Sat, 2 Apr 2022 16:14:37 +0000 (17:14 +0100)
This updates the custom Request handler to provide only the scheme and
host on the `getSchemeAndHttpHost` call, instead of providing the whole
APP_URL value, while adding an override to the 'getBaseUrl' to use the
APP_URL content instead of the guessed/detected Symfony value.

Untested apart from simple local setup.

Related to #2765

app/Http/Request.php

index c5b38f1c1bbfe1f391469d791d144ed400e1ce38..687bae9a6cb196e221d9c84ca33f3159da01f2ab 100644 (file)
@@ -8,20 +8,35 @@ 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.
+     *
+     * @return string
+     */
+    public function getBaseUrl()
+    {
+        $appUrl = config('app.url', null);
+
+        if ($appUrl) {
+            return rtrim(implode('/', array_slice(explode('/', $appUrl), 3)), '/');
+        }
+
+        return parent::getBaseUrl();
     }
 }