mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
FIX: disable x accl redirect for CDN assets
We need to keep headers in tact
This commit is contained in:
parent
e4a7f652cc
commit
5032c96486
@ -73,6 +73,10 @@ class StaticController < ApplicationController
|
|||||||
disposition: nil
|
disposition: nil
|
||||||
}
|
}
|
||||||
opts[:type] = "application/x-javascript" if path =~ /\.js$/
|
opts[:type] = "application/x-javascript" if path =~ /\.js$/
|
||||||
|
|
||||||
|
# we must disable acceleration otherwise NGINX strips
|
||||||
|
# access control headers
|
||||||
|
request.env['_disable_accl'] = true
|
||||||
send_file(path, opts)
|
send_file(path, opts)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -15,7 +15,7 @@ module ApplicationHelper
|
|||||||
if SiteSetting.enable_cdn_js_debugging && GlobalSetting.cdn_url
|
if SiteSetting.enable_cdn_js_debugging && GlobalSetting.cdn_url
|
||||||
tags = javascript_include_tag(*args, "crossorigin" => "anonymous")
|
tags = javascript_include_tag(*args, "crossorigin" => "anonymous")
|
||||||
tags.gsub!("/assets/", "/cdn_asset/#{Discourse.current_hostname.gsub(".","_")}/")
|
tags.gsub!("/assets/", "/cdn_asset/#{Discourse.current_hostname.gsub(".","_")}/")
|
||||||
tags.gsub!(".js\"", ".js?origin=#{CGI.escape request.base_url}\"")
|
tags.gsub!(".js\"", ".js?v=1&origin=#{CGI.escape request.base_url}\"")
|
||||||
tags.html_safe
|
tags.html_safe
|
||||||
else
|
else
|
||||||
javascript_include_tag(*args)
|
javascript_include_tag(*args)
|
||||||
|
@ -11,7 +11,7 @@
|
|||||||
<%- end %>
|
<%- end %>
|
||||||
|
|
||||||
<%= script "preload_store" %>
|
<%= script "preload_store" %>
|
||||||
<%= javascript_include_tag "locales/#{I18n.locale}" %>
|
<%= script "locales/#{I18n.locale}" %>
|
||||||
<%= script "vendor" %>
|
<%= script "vendor" %>
|
||||||
<%= script "application" %>
|
<%= script "application" %>
|
||||||
<%- if staff? %>
|
<%- if staff? %>
|
||||||
|
@ -122,6 +122,13 @@ module Discourse
|
|||||||
# supports etags (post 1.7)
|
# supports etags (post 1.7)
|
||||||
config.middleware.delete Rack::ETag
|
config.middleware.delete Rack::ETag
|
||||||
|
|
||||||
|
# We need to be able to disable for cdn assets
|
||||||
|
# x-accl-redirect strips headers we need to forward
|
||||||
|
# issue open since 2008
|
||||||
|
require 'middleware/optional_sendfile'
|
||||||
|
config.middleware.insert_after Rack::Sendfile, Middleware::OptionalSendfile, config.action_dispatch.x_sendfile_header
|
||||||
|
config.middleware.delete Rack::Sendfile
|
||||||
|
|
||||||
# route all exceptions via our router
|
# route all exceptions via our router
|
||||||
config.exceptions_app = self.routes
|
config.exceptions_app = self.routes
|
||||||
|
|
||||||
|
11
lib/middleware/optional_sendfile.rb
Normal file
11
lib/middleware/optional_sendfile.rb
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
module Middleware
|
||||||
|
class OptionalSendfile < Rack::Sendfile
|
||||||
|
def call(env)
|
||||||
|
if env["_disable_accl"] == true
|
||||||
|
@app.call(env)
|
||||||
|
else
|
||||||
|
super(env)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in New Issue
Block a user