Last active
August 29, 2015 14:06
-
-
Save jmoe/2c1ac03d0f5cc02ee2be to your computer and use it in GitHub Desktop.
Revisions
-
jmoe revised this gist
Sep 8, 2014 . 1 changed file with 25 additions and 13 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,31 +1,43 @@ namespace :fastly do desc "set fastly cors headers to fix chrome/firefox font loading issues" task allow_cors: :environment do # check for the Cors Allow header versions = Yajl.load(Excon.get("https://api.fastly.com/service/#{ENV['FASTLY_SERVICE_ID']}/version", :headers => {'Fastly-Key'=>ENV['FASTLY_API_KEY']}).body) last_version = versions.last['number'] exists = Excon.get("https://api.fastly.com/service/#{ENV['FASTLY_SERVICE_ID']}/version/#{last_version}/header/Cors%20Allow", :headers => {'Fastly-Key'=>ENV['FASTLY_API_KEY']}).status if(exists == 200) puts "Allow Cors already set. Done." else cloned = Yajl.load(Excon.put("https://api.fastly.com/service/#{ENV['FASTLY_SERVICE_ID']}/version/#{last_version}/clone", :headers => {'Fastly-Key'=>ENV['FASTLY_API_KEY']}).body) cloned_version = cloned['number'] puts cloned response = Yajl.load(Excon.post("https://api.fastly.com/service/#{ENV['FASTLY_SERVICE_ID']}/version/#{cloned_version}/header", :headers => {'Fastly-Key'=>ENV['FASTLY_API_KEY']}, :body => 'name=Cors Allow&type=response&action=set&dst=http.Access-Control-Allow-Origin&src="*"&ignore_if_set=0&priority=10').body) puts response activated = Excon.put("https://api.fastly.com/service/#{ENV['FASTLY_SERVICE_ID']}/version/#{cloned_version}/activate", :headers => {'Fastly-Key'=>ENV['FASTLY_API_KEY']}).status if(activated == 200) puts "Allow Cors header set. Done." end end end end -
jmoe created this gist
Sep 8, 2014 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,31 @@ namespace :fastly do desc "set fastly cors headers to fix chrome/firefox font loading issues" task apply_cors_header: :environment do versions = Yajl.load(Excon.get("https://api.fastly.com/service/#{ENV['FASTLY_SERVICE_ID']}/version", :headers => {'Fastly-Key'=>ENV['FASTLY_API_KEY']}).body) last_version = versions.last['number'] puts versions cloned = Yajl.load(Excon.put("https://api.fastly.com/service/#{ENV['FASTLY_SERVICE_ID']}/version/#{last_version}/clone", :headers => {'Fastly-Key'=>ENV['FASTLY_API_KEY']}).body) cloned_version = cloned['number'] puts cloned response = Yajl.load(Excon.post("https://api.fastly.com/service/#{ENV['FASTLY_SERVICE_ID']}/version/#{cloned_version}/header", :headers => {'Fastly-Key'=>ENV['FASTLY_API_KEY']}, :body => 'name=Cors Allow&type=response&action=set&dst=http.Access-Control-Allow-Origin&src="*"&ignore_if_set=0&priority=10').body) puts response activated = Yajl.load(Excon.put("https://api.fastly.com/service/#{ENV['FASTLY_SERVICE_ID']}/version/#{cloned_version}/activate", :headers => {'Fastly-Key'=>ENV['FASTLY_API_KEY']}).body) puts activated end end