From 969fca60662429d55216bc5854a972f8548aeaf6 Mon Sep 17 00:00:00 2001 From: An Phan Date: Mon, 14 Mar 2016 10:36:03 +0800 Subject: [PATCH] Return full asset URLs --- app/Application.php | 6 ++++-- tests/ApplicationTest.php | 6 +++--- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/app/Application.php b/app/Application.php index 14fea835..86c0ede5 100644 --- a/app/Application.php +++ b/app/Application.php @@ -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)); } /** diff --git a/tests/ApplicationTest.php b/tests/ApplicationTest.php index c58b9096..36fac632 100644 --- a/tests/ApplicationTest.php +++ b/tests/ApplicationTest.php @@ -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');