From 50e855bb71d111113def7fb1b81643d436921403 Mon Sep 17 00:00:00 2001 From: Pig Fang Date: Sun, 31 Mar 2019 14:38:17 +0800 Subject: [PATCH] Fix loading resources from CDN --- app/Services/Webpack.php | 2 +- app/helpers.php | 3 ++- tests/AdminControllerTest.php | 2 +- tests/ServicesTest/WebpackTest.php | 2 +- 4 files changed, 5 insertions(+), 4 deletions(-) diff --git a/app/Services/Webpack.php b/app/Services/Webpack.php index a421ee53..54748dc0 100644 --- a/app/Services/Webpack.php +++ b/app/Services/Webpack.php @@ -19,6 +19,6 @@ class Webpack public function __get($path) { - return url('app').'/'.Arr::get($this->manifest, $path, ''); + return Arr::get($this->manifest, $path, ''); } } diff --git a/app/helpers.php b/app/helpers.php index 7d50e963..60959d7a 100644 --- a/app/helpers.php +++ b/app/helpers.php @@ -33,8 +33,9 @@ if (! function_exists('webpack_assets')) { return "http://127.0.0.1:8080/public/$relativeUri"; // @codeCoverageIgnoreEnd } else { + $path = app('webpack')->$relativeUri; $cdn = option('cdn_address'); - return $cdn ? "$cdn/app/$relativeUri" : app('webpack')->$relativeUri; + return $cdn ? "$cdn/app/$path" : url("/app/$path"); } } } diff --git a/tests/AdminControllerTest.php b/tests/AdminControllerTest.php index f20e56de..dd3a41be 100644 --- a/tests/AdminControllerTest.php +++ b/tests/AdminControllerTest.php @@ -192,7 +192,7 @@ class AdminControllerTest extends BrowserKitTestCase $this->assertFalse(option('auto_detect_asset_url')); $this->assertTrue(option('return_204_when_notfound')); $this->assertEquals('0', option('cache_expire_time')); - $this->visit('/')->see('url/app/index.js'); + $this->visit('/')->see('url/app/'); $this->visit('/admin/resource') ->type('', 'cdn_address') diff --git a/tests/ServicesTest/WebpackTest.php b/tests/ServicesTest/WebpackTest.php index cbad07cb..7f9cdac9 100644 --- a/tests/ServicesTest/WebpackTest.php +++ b/tests/ServicesTest/WebpackTest.php @@ -12,6 +12,6 @@ class WebpackTest extends TestCase File::shouldReceive('exists')->andReturn(true); File::shouldReceive('get')->andReturn(json_encode(['a' => 'b'])); $key = 'a'; - $this->assertEquals('http://localhost/app/b', app('webpack')->$key); + $this->assertEquals('b', app('webpack')->$key); } }