How to get a CDN to work for Staging and Production ENVs, using CloudFront, Rails, Jammit
-
08-01-2021 - |
문제
I just hooked Amazon's CLoudfront CDN up to our app.
In the staging and production.rb file, in rails all it took was:
config.action_controller.asset_host = Proc.new { |source, request|
if request.ssl?
"https://cfIDhere.cloudfront.net"
else
# Pick a random CDN
"http://cdn0#{source.hash % 4}.mysite.com"
end
}
The challenge now is that both production and staging envs both call this:
http://cdn02.mysite.com/assets/application.js
That's going to create so crazy issues. What's the best way to handle making the CDN work for both Prod and Staging?
I'd love to be able to do something like this:
http://cdn02.mysite.com/assets/production/application.js
http://cdn02.mysite.com/assets/staging/application.js
Anyone have any experience with this? Thanks
올바른 솔루션이 없습니다
다른 팁
I would segregate your CDNs by environment. So CDN{\d\d} would be production, then app-stage-cdn{\d\d} would be staging.
제휴하지 않습니다 StackOverflow