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