AnApprentice
AnApprentice

Reputation: 110980

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

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

Upvotes: 4

Views: 1601

Answers (1)

Daniel Evans
Daniel Evans

Reputation: 6808

I would segregate your CDNs by environment. So CDN{\d\d} would be production, then app-stage-cdn{\d\d} would be staging.

Upvotes: 1

Related Questions