Browse Source

Merge pull request #578 from cviebrock/asset-url

Configuration option to set different base URL for assets
Taylor Otwell 12 years ago
parent
commit
48dae0c3d9
3 changed files with 27 additions and 1 deletions
  1. 14 0
      application/config/application.php
  2. 1 1
      laravel/bundle.php
  3. 12 0
      laravel/url.php

+ 14 - 0
application/config/application.php

@@ -15,6 +15,20 @@ return array(
 
 
 	'url' => '',
 	'url' => '',
 
 
+	/*
+	|--------------------------------------------------------------------------
+	| Asset URL
+	|--------------------------------------------------------------------------
+	|
+	| The base URL used for your application's asset files, if you are serving
+	| them through a different server or a content delivery network, for
+	| example. If it's not set, we'll default to the application URL (above).
+	| Leave off the trailing slash.
+	|
+	*/
+
+	'asset_url' => '',
+
 	/*
 	/*
 	|--------------------------------------------------------------------------
 	|--------------------------------------------------------------------------
 	| Application Index
 	| Application Index

+ 1 - 1
laravel/bundle.php

@@ -297,7 +297,7 @@ class Bundle {
 	{
 	{
 		if (is_null($bundle)) return static::assets(DEFAULT_BUNDLE);
 		if (is_null($bundle)) return static::assets(DEFAULT_BUNDLE);
 
 
-		return ($bundle != DEFAULT_BUNDLE) ? URL::base()."/bundles/{$bundle}/" : URL::base().'/';
+		return ($bundle != DEFAULT_BUNDLE) ? "/bundles/{$bundle}/" : '/';
 	}
 	}
 
 
 	/**
 	/**

+ 12 - 0
laravel/url.php

@@ -220,6 +220,18 @@ class URL {
 	 */
 	 */
 	public static function to_asset($url, $https = null)
 	public static function to_asset($url, $https = null)
 	{
 	{
+
+		// If the URL is already well-formed, just return it
+		if (static::valid($url)) return $url;
+
+		// If a base asset URL is defined in the configuration, use that and
+		// don't try and change links to http/https.
+		if ($root = Config::get('application.asset_url', false )) {
+
+			return rtrim($root, '/').'/'.ltrim($url, '/');
+
+		}
+
 		if (is_null($https)) $https = Request::secure();
 		if (is_null($https)) $https = Request::secure();
 
 
 		$url = static::to($url, $https);
 		$url = static::to($url, $https);