Fix loading resources from CDN

This commit is contained in:
Pig Fang 2019-03-31 14:38:17 +08:00
parent 92dbca70d4
commit 50e855bb71
4 changed files with 5 additions and 4 deletions

View File

@ -19,6 +19,6 @@ class Webpack
public function __get($path)
{
return url('app').'/'.Arr::get($this->manifest, $path, '');
return Arr::get($this->manifest, $path, '');
}
}

View File

@ -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");
}
}
}

View File

@ -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')

View File

@ -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);
}
}