-
-
Save DonKoko/9d240bb3d4bdf6a47de4104507bdbdbd to your computer and use it in GitHub Desktop.
Some rack middleware to add headers to asset pipeline.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class AssetHeaders | |
def initialize(app) | |
@app = app | |
end | |
def call(env) | |
request = Rack::Request.new(env) | |
response = @app.call(env) | |
if request.path =~ /^\/assets\// | |
# there maybe a better way to add headers | |
response[1]["Access-Control-Allow-Origin"] = "*" | |
end | |
response | |
end | |
end | |
Railscasts::Application.configure do | |
config.middleware.use "AssetHeaders" | |
# ... | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment