ruby - Rerouting to AWS hosted assets from a Heroku Rails app -
i have heroku hosted rails app has reached 300mb limit slug size , can no push heroku. fix issue, i've setup aws s3 account , want redirect assets being requested rails app new s3 location. rails app serving json files point static assets using relative url. ios app using rails json has hardcoded domain url, , appends path resources domain , requests assets needs.
i want update heroku app , change asset locations without requiring update ios app in order change asset domain. so, need redirect static asset requests rails app aws server.
in git repo, i've ignored assets in public folder i've moved aws server. asset files present on local machine, not part of git repo when uploaded heroku.
so far i've tried changing config.action_controller.asset_host
not seem work since these static assets , being returned web server before rails gets it.
i tried using routes rules redirect different domain, these routes never seem captured. static files appear returned before rails app has chance handle request.
i've tried using rack-rewrite
gem try , redirect assets different domain following in `initializers/rack_rewrite.rb:
require 'rack/rewrite' appnamespace::application.config.middleware.insert_before(rack::lock, rack::rewrite) r301 %r{/images(.*)}, 'http://my-subdomain.amazonaws.com/images$1' end
this doesn't seem work either , returns static files.
so far i've been trying hours figure out proper way handle situation. i'm not rails developer trade, build ios apps, please let me know if i'm going wrong way or missed "right" way of doing this.
i solved using routes , 'rails_serve_static_assets'. had move local images out of public folder in order avoid nginx returning images before hitting rails app. route ended so:
match '/images/(*path)', :to => redirect { |params, request| "#{rails.configuration.assets.aws_url}#{request.path}" }
Comments
Post a Comment