Setting custom headers for assets in Rails on Heroku cedars

I have a cedar application that uses Rails 4.0 and an asset pipeline. I would like to set my own headers for all assets from the asset pipeline. How can I do that?

+4
source share
1 answer

An easy way would be to use a plugin with plugins, something like this:

class RackAssetFilter def initialize app @app = app end def call env @status, @headers, @body = @app.call env if env['PATH_INFO'].starts_with?( "/assets/" ) @headers['X-Header-1'] = 'value' # ... end return [@status, @headers, @body] end end 

To enable it, in application.rb:

 config.middleware.insert_before( ActionDispatch::Static, RackAssetFilter ) 

Keep in mind that you need to declare or load a RackAssetFilter with a request before pushing it onto the middleware stack in application.rb

+3
source

Source: https://habr.com/ru/post/1490228/


All Articles