2
0
Fork 0
mirror of https://github.com/discourse/discourse.git synced 2025-09-08 12:06:51 +08:00
discourse/lib/middleware/apply_cdn.rb

25 lines
536 B
Ruby
Raw Normal View History

module Middleware
class ApplyCDN
def initialize(app, settings={})
@app = app
end
def call(env)
status, headers, response = @app.call(env)
if Discourse.asset_host.present? &&
Discourse.store.external? &&
(headers["Content-Type"].start_with?("text/") ||
headers["Content-Type"].start_with?("application/json"))
response.body = response.body.gsub(Discourse.store.absolute_base_url, Discourse.asset_host)
end
[status, headers, response]
end
end
end