Return full asset URLs

This commit is contained in:
An Phan 2016-03-14 10:36:03 +08:00
parent 01480432a8
commit 969fca6066
2 changed files with 7 additions and 5 deletions

View file

@ -59,7 +59,7 @@ class Application extends IlluminateApplication
/**
* Get a URL for static file requests.
* If this installation of Koel has a CDN_URL configured, use it as the base.
* Otherwise, just use a relative '/'.
* Otherwise, just use a full URL to the asset.
*
* @param string $name The additional resource name/path.
*
@ -67,7 +67,9 @@ class Application extends IlluminateApplication
*/
public function staticUrl($name = null)
{
return trim(env('CDN_URL'), '/ ').'/'.trim(ltrim($name, '/'));
$cdnUrl = trim(env('CDN_URL'), '/ ');
return $cdnUrl ? $cdnUrl.'/'.trim(ltrim($name, '/')) : trim(asset($name));
}
/**

View file

@ -11,8 +11,8 @@ class ApplicationTest extends TestCase
{
putenv('CDN_URL');
$this->assertEquals(App::staticUrl(), '/');
$this->assertEquals(App::staticUrl('foo.css '), '/foo.css');
$this->assertEquals(App::staticUrl(), 'http://localhost/');
$this->assertEquals(App::staticUrl('foo.css '), 'http://localhost/foo.css');
}
public function testStaticUrlWithCDN()
@ -28,7 +28,7 @@ class ApplicationTest extends TestCase
putenv('CDN_URL');
$manifestFile = dirname(__FILE__).'/blobs/rev-manifest.json';
$this->assertEquals(App::rev('foo.css', $manifestFile), '/public/build/foo00.css');
$this->assertEquals(App::rev('foo.css', $manifestFile), 'http://localhost/public/build/foo00.css');
putenv('CDN_URL=http://cdn.bar');
$this->assertEquals(App::rev('bar.js', $manifestFile), 'http://cdn.bar/public/build/bar00.js');