Skip to content

Instantly share code, notes, and snippets.

@choonkeat
Last active August 29, 2015 14:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save choonkeat/31d5a6bcdc6f05e005ce to your computer and use it in GitHub Desktop.
Save choonkeat/31d5a6bcdc6f05e005ce to your computer and use it in GitHub Desktop.
make "GET /assets/yourfile.css" redirect to the correct "<asset host>/assets/yourfile<-digest suffix>.css" url
match "/assets/*path" => lambda {|env|
path = env['REQUEST_PATH']
Rails.cache.fetch("v9.assets.#{path}", expires_in: 1.hour) do
if found = Rails.application.assets.find_asset(File.basename(path))
[302, { 'Location' => "#{Rails.application.config.action_controller.asset_host}#{File.dirname(path)}/#{found.digest_path}" }, []]
else
[404, {}, []]
end
end
}, via: [:get] # /lambda
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment