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
|
||||
}
|
||||
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)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -15,7 +15,7 @@ module ApplicationHelper
|
|||
if SiteSetting.enable_cdn_js_debugging && GlobalSetting.cdn_url
|
||||
tags = javascript_include_tag(*args, "crossorigin" => "anonymous")
|
||||
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
|
||||
else
|
||||
javascript_include_tag(*args)
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
<%- end %>
|
||||
|
||||
<%= script "preload_store" %>
|
||||
<%= javascript_include_tag "locales/#{I18n.locale}" %>
|
||||
<%= script "locales/#{I18n.locale}" %>
|
||||
<%= script "vendor" %>
|
||||
<%= script "application" %>
|
||||
<%- if staff? %>
|
||||
|
|
|
@ -122,6 +122,13 @@ module Discourse
|
|||
# supports etags (post 1.7)
|
||||
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
|
||||
config.exceptions_app = self.routes
|
||||
|
||||
|
|
|
@ -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