Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Updating for AWS cloudfront HTTPS support

  • Loading branch information...
commit b55ba42eae8fccb290a62b3b9afa0764bb21b029 1 parent dc0cec6
@adamburmister authored
View
23 README.textile
@@ -64,15 +64,21 @@ production:
h3. Set up an asset_host
For each environment that you'd like to utilise the CloudFront CDN for you'll need to define the asset_host within the @config/environments/{ENVIRONMENT}.rb@ configuration file.
-In my projects I've used the AssetHostingWithMinimumSsl plugin to ensure that you're switching between HTTP and HTTPS as required.
-h4. Example config/environments/production.rb @asset_host@ snippet using AssetHostingWithMinimumSsl:
+As of June 2010 AWS supports HTTPS requests on the CloudFront CDN, so you no longer have to worry about switching servers. (Yay!)
+
+h4. Example config/environments/production.rb @asset_host@ snippet:
+
+Here we're targeting a CNAME domain with HTTP support.
<pre>
-config.action_controller.asset_host = AssetHostingWithMinimumSsl.new(
- "http://cdn%d.app.yoursite.com",
- "https://www.yoursite.com"
-)
+ActionController::Base.asset_host = Proc.new { |source, request|
+ if request.ssl?
+ "#{request.protocol}#{request.host_with_port}"
+ else
+ "#{request.protocol}assets.example.com"
+ end
+}
</pre>
@@ -89,11 +95,6 @@ h3. AWS S3
Required for uploading the assets to the Amazon Web Services S3 buckets.
See "http://amazon.rubyforge.org/":http://amazon.rubyforge.org/ for more documentation on installation.
-h3. AssetHostingWithMinimumSsl (optional)
-
-Used to deal with switching between HTTP and HTTPS asset hosts, ensuring you serve non-HTTPS traffic from the fast CDN, and secure assets from your SSL signed web server.
-See "http://github.com/dhh/asset-hosting-with-minimum-ssl":http://github.com/dhh/asset-hosting-with-minimum-ssl.
-
h2. About the name
Perhaps not what you'd expect; a "Morning Glory":http://en.wikipedia.org/wiki/Morning_Glory_cloud is a rare cloud formation observed by glider pilots in Australia (see my side project, "YourFlightLog.com for flight-logging software for paraglider and hang-glider pilots":http://www.yourflightlog.com, from which the Morning Glory plugin was originally extracted).
View
15 lib/asset_tag_helper.rb
@@ -7,12 +7,15 @@ def rewrite_asset_path(source)
if asset_id.blank?
source
else
- # If the request isn't SSL, or if the request is SSL and the SSL host is set
- if !request.ssl? || (request.ssl? && !AssetHostingWithMinimumSsl::asset_ssl_host.empty?)
- File.join('/', ENV['RAILS_ASSET_ID'], source)
- else
- source + "?#{asset_id}"
- end
+ # AB: As of June AWS Cloudfront supports HTTPS requests. This alternative code path should now be redundant.
+ # # If the request isn't SSL, or if the request is SSL and the SSL host is set
+ # if !request.ssl? || (request.ssl? && !AssetHostingWithMinimumSsl::asset_ssl_host.empty?)
+ # File.join('/', ENV['RAILS_ASSET_ID'], source)
+ # else
+ # source + "?#{asset_id}"
+ # end
+
+ File.join('/', ENV['RAILS_ASSET_ID'], source)
end
end
View
17 lib/tasks/morning_glory.rake
@@ -4,8 +4,7 @@ namespace :morning_glory do
namespace :cloudfront do
@@prev_cdn_revision = nil
- @@scm_commit_required = false
-
+
begin
MORNING_GLORY_CONFIG = YAML.load_file("#{RAILS_ROOT}/config/morning_glory.yml") if !defined? MORNING_GLORY_CONFIG
rescue
@@ -27,7 +26,8 @@ namespace :morning_glory do
begin
git_rev = `git show --pretty=format:"%H|%ci" --quiet`.split('|')[0]
if !git_rev.nil?
- rev = git_rev.to_s
+ rev = git_rev
+ puts rev
puts '* Using Git revision'
end
rescue
@@ -38,7 +38,7 @@ namespace :morning_glory do
svn_rev = `svnversion .`.chomp.gsub(':','_')
puts svn_rev
if svn_rev != 'exported' && svn_rev != '' && svn_rev != nil
- rev = Digest::MD5.hexdigest( svn_rev ).to_s
@adamburmister Owner

Shit, shouldn't have reverted this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+ rev = Digest::MD5.hexdigest( svn_rev )
puts '* Using SVN revision'
end
rescue
@@ -48,7 +48,6 @@ namespace :morning_glory do
if rev.nil?
rev = Time.new.strftime("%Y%m%d%H%M%S")
puts '* Using timestamp revision'
- @@scm_commit_required = true
end
return rev
@@ -139,7 +138,7 @@ namespace :morning_glory do
)
begin
- puts "* Attempting to create S3 Bucket '#{BUCKET}'"
+ puts "* Attempting to creating S3 Bucket '#{BUCKET}'"
AWS::S3::Bucket.create(BUCKET)
AWS::S3::Bucket.enable_logging_for(BUCKET) if S3_LOGGING_ENABLED
@@ -175,12 +174,6 @@ namespace :morning_glory do
end
puts "MorningGlory: DONE! Your assets have been deployed to the Cloudfront CDN."
-
- if @@scm_commit_required == true
- puts '='*80
- puts "NB: You will need to commit the /config/morning_glory.yml file and update it on your servers."
- puts '='*80
- end
end
end
end

1 comment on commit b55ba42

@jgarber

Very nice! If I'd have known Amazon was releasing it yesterday, I wouldn't have spent 8 hours last week making AssetHostingWithMinimumSsl work! :-) Thanks for adapting your code so quickly!

Please sign in to comment.
Something went wrong with that request. Please try again.