开发者

How to get a CDN to work for Staging and Production ENVs, using CloudFront, Rails, Jammit

I just hooked Amazon's CLoudfront CDN up开发者_StackOverflow中文版 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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜