mirror of
https://github.com/discourse/discourse.git
synced 2025-09-08 12:06:51 +08:00
25 lines
536 B
Ruby
25 lines
536 B
Ruby
|
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
|