Skip to content

Instantly share code, notes, and snippets.

@DonKoko
Forked from ryanb/development.rb
Created January 23, 2020 16:06
Show Gist options
  • Save DonKoko/9d240bb3d4bdf6a47de4104507bdbdbd to your computer and use it in GitHub Desktop.
Save DonKoko/9d240bb3d4bdf6a47de4104507bdbdbd to your computer and use it in GitHub Desktop.
Some rack middleware to add headers to asset pipeline.
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