]> BookStack Code Mirror - bookstack/commitdiff
Fixed URL gen issue causing incorrect scheme to be used
authorDan Brown <redacted>
Sun, 1 Sep 2019 11:07:51 +0000 (12:07 +0100)
committerDan Brown <redacted>
Sun, 1 Sep 2019 11:07:51 +0000 (12:07 +0100)
For #1613

app/Providers/AppServiceProvider.php
tests/Unit/UrlTest.php

index a2fc673f488fc1de45bb27a0f4a48e2790bc9cf6..b46a716cc4e0e985b287f233437b66eafcca7357 100644 (file)
@@ -25,7 +25,12 @@ class AppServiceProvider extends ServiceProvider
     public function boot()
     {
         // Set root URL
-        URL::forceRootUrl(config('app.url'));
+        $appUrl = config('app.url');
+        if ($appUrl) {
+            $isHttps = (strpos($appUrl, 'https://') === 0);
+            URL::forceRootUrl($appUrl);
+            URL::forceScheme($isHttps ? 'https' : 'http');
+        }
 
         // Custom validation methods
         Validator::extend('image_extension', function ($attribute, $value, $parameters, $validator) {
index c7d33312c4c0dccc2ca5f2e3f421cb0941703d24..1667f5f7bab683c26b32a01ce9b4434e7679bed7 100644 (file)
@@ -22,4 +22,12 @@ class UrlTest extends TestCase
         putenv('APP_URL=');
     }
 
+    public function test_url_helper_sets_correct_scheme_even_when_request_scheme_is_different()
+    {
+        putenv('APP_URL=https://example.com/');
+        $this->refreshApplication();
+        $this->get('http://example.com/login')->assertSee('https://example.com/dist/styles.css');
+        putenv('APP_URL=');
+    }
+
 }
\ No newline at end of file