From 24102f26365d08208702061d13adb93c76d058f3 Mon Sep 17 00:00:00 2001 From: Sam Date: Wed, 27 May 2015 12:59:51 +1000 Subject: [PATCH] FIX: apply s3 cdn to client side assets --- app/assets/javascripts/discourse.js | 7 ++++++- app/views/common/_discourse_javascript.html.erb | 6 ++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/app/assets/javascripts/discourse.js b/app/assets/javascripts/discourse.js index 5a6cf9282..da97ad531 100644 --- a/app/assets/javascripts/discourse.js +++ b/app/assets/javascripts/discourse.js @@ -32,7 +32,12 @@ window.Discourse = Ember.Application.createWithMixins(Discourse.Ajax, { getURLWithCDN: function(url) { url = this.getURL(url); - if (Discourse.CDN) { url = Discourse.CDN + url; } + // https:// and http:// and // should be skipped, only /xyz is allowed here + if (Discourse.CDN && url[1] !== "/") { + url = Discourse.CDN + url; + } else if (Discourse.S3CDN) { + url = url.replace(Discourse.S3BaseUrl, Discourse.S3CDN); + } return url; }, diff --git a/app/views/common/_discourse_javascript.html.erb b/app/views/common/_discourse_javascript.html.erb index a07556305..98332fec1 100644 --- a/app/views/common/_discourse_javascript.html.erb +++ b/app/views/common/_discourse_javascript.html.erb @@ -40,6 +40,12 @@ Discourse.set('assetVersion','<%= Discourse.assets_digest %>'); Discourse.Session.currentProp("disableCustomCSS", <%= loading_admin? %>); Discourse.HighlightJSPath = <%= HighlightJs.path.inspect.html_safe %>; + <%- if SiteSetting.enable_s3_uploads %> + <%- if SiteSetting.s3_cdn_url.present? %> + Discourse.S3CDN = '<%= SiteSetting.s3_cdn_url %>'; + <%- end %> + Discourse.S3BaseUrl = '<%= Discourse.store.absolute_base_url %>'; + <%- end %> <%= script 'browser-update' %>