thesis_cloudfront 0.2.0 → 0.2.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e3a2935355f22f904c01cb1d5334579bd70725ea4fc77ed3317bde209a5e2e47
4
- data.tar.gz: aa46b3d66aaab086ca5b0ebae1f6a640208a8832bff2bf86ec16e16d433bac7d
3
+ metadata.gz: 6d5f7a41ee42054f868406127c6a62a40f4c6e4a72266277e34b84c657ceaf98
4
+ data.tar.gz: 0cd45b65149c83c50dce32738cfe8dd3d1bed840710afd96f31547e6632dbf9f
5
5
  SHA512:
6
- metadata.gz: bb56fc15d9c745fdc9257c66a9465a8db615d34049777e2c89ace38ed3fd1c822ed6a60170498e445e8c51ca7e23622af68822557b94c4d93a4e7f91b0f0f285
7
- data.tar.gz: 58907e162be1a1ad87246f3329a7e572cd38a22ed2b665cb81240e537d220faaa6368cc12f1b04ac9ad78ae1541705ffd76f9cd08deff2a99f63de87ee4ab747
6
+ metadata.gz: fd707c28768aa48d6d144d51f7eaaef5b600322daffd577101d9386845894fd4931102c8c4073eb729b5e00129c00d9819b5ddb38f0620a94980084dc3be3795
7
+ data.tar.gz: 7e1126148b948c17c0fd110f189cc9c2c95be45c5eb89ba1b75aa7bea6160f02afa699a6924c2e942bd5a9897e3e5070f8d3cd44d7ce460b1fc3d2b5a53fd0dc
data/README.md CHANGED
@@ -1,8 +1,7 @@
1
1
  # ThesisCloudfront
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/thesis_cloudfront`. To experiment with that code, run `bin/console` for an interactive prompt.
4
-
5
- TODO: Delete this and the text above, and describe your gem
3
+ assumes you are using heroku for CNAME capturing purposes (through the cli), if not it'll skip that step.
4
+ If you aren't using Heroku I highly recommend you check out the rack_cors.rb initializer that's generated and edit it for your purposes.
6
5
 
7
6
  ## Installation
8
7
 
@@ -22,7 +21,7 @@ Or install it yourself as:
22
21
 
23
22
  ## Usage
24
23
 
25
- TODO: Write usage instructions here
24
+ run `rails g thesis_cloudfront:install`
26
25
 
27
26
  ## Development
28
27
 
@@ -1,14 +1,23 @@
1
1
  require 'rails/generators'
2
+ require 'csv'
2
3
 
3
4
  module ThesisCloudfront
4
5
  module Generators
5
6
  class InstallGenerator < Rails::Generators::Base
6
7
  def install
7
- append_to_file "Gemfile" do
8
- "\ngem 'rack_cors'"
9
- end
10
-
11
8
  heroku_app_name = ask("whats the name of this heroku app?")
9
+ file = `heroku domains -a #{heroku_app_name} --csv`
10
+ file&.gsub!(/===.+|.+\.herokuapp.com/, '').strip
11
+ domains = []
12
+
13
+ if file
14
+ CSV.parse(file, headers: true).each do |x|
15
+ if x['Domain Name']
16
+ domains << ' /https:\/\/' + "#{x['Domain Name']}/"
17
+ domains << ' /http:\/\/' + "#{x['Domain Name']}/"
18
+ end
19
+ end
20
+ end
12
21
 
13
22
  create_file "config/initializers/rack_cors.rb" do
14
23
  ["Rails.application.config.middleware.insert_before 0, Rack::Cors do",
@@ -16,16 +25,20 @@ module ThesisCloudfront
16
25
  " origins [",
17
26
  " /https:\\/\\/#{heroku_app_name}.herokuapp.com/,",
18
27
  " /http:\\/\\/#{heroku_app_name}.herokuapp.com/,",
19
- " /https:\\/\\/#{heroku_app_name}-pr-[0-9]+.herokuapp.com/,",
20
- " /http:\\/\\/#{heroku_app_name}-pr-[0-9]+.herokuapp.com/",
28
+ " /https:\\/\\/#{heroku_app_name}-pr-.+.herokuapp.com/,",
29
+ " /http:\\/\\/#{heroku_app_name}-pr-.+.herokuapp.com/,", domains.join(",\n"),
21
30
  " ]",
22
31
  " resource '/assets/*', headers: :any, methods: [:get, :head, :options]",
23
32
  " end",
24
33
  "end"].join("\n")
25
34
  end
26
35
 
27
- create_file "config/initializers/asset_host.rb" do
28
- "ActionController::Base.asset_host = ENV['CLOUDFRONT_URL']"
36
+ create_file "config/initializers/cloudfront.rb" do
37
+ ["ActionController::Base.asset_host = ENV['CLOUDFRONT_URL']",
38
+ "Rails.application.config.public_file_server.headers = {",
39
+ " 'Cache-Control' => 'public, max-age=2592000',",
40
+ ' "Expires" => "#{30.days.from_now.to_formatted_s(:rfc822)}"',
41
+ "}"].join("\n")
29
42
  end
30
43
  end
31
44
  end
@@ -0,0 +1,50 @@
1
+ require 'rails/generators'
2
+ require 'csv'
3
+
4
+ module Cloudfront
5
+ module Generators
6
+ class InstallGenerator < Rails::Generators::Base
7
+ def install
8
+ # append_to_file "Gemfile" do
9
+ # "\ngem 'rack-cors'"
10
+ # end
11
+
12
+ heroku_app_name = ask("whats the name of this heroku app?")
13
+ file = `heroku domains -a #{heroku_app_name} --csv`
14
+ file&.gsub!(/===.+|.+\.herokuapp.com/, '').strip
15
+ domains = []
16
+
17
+ if file
18
+ CSV.parse(file, headers: true).each do |x|
19
+ if x['Domain Name']
20
+ domains << ' /https:\/\/' + "#{x['Domain Name']}/"
21
+ domains << ' /http:\/\/' + "#{x['Domain Name']}/"
22
+ end
23
+ end
24
+ end
25
+
26
+ create_file "config/initializers/rack_cors.rb" do
27
+ ["Rails.application.config.middleware.insert_before 0, Rack::Cors do",
28
+ " allow do",
29
+ " origins [",
30
+ " /https:\\/\\/#{heroku_app_name}.herokuapp.com/,",
31
+ " /http:\\/\\/#{heroku_app_name}.herokuapp.com/,",
32
+ " /https:\\/\\/#{heroku_app_name}-pr-\w+.herokuapp.com/,",
33
+ " /http:\\/\\/#{heroku_app_name}-pr-\w+.herokuapp.com/,", domains.join(",\n"),
34
+ " ]",
35
+ " resource '/assets/*', headers: :any, methods: [:get, :head, :options]",
36
+ " end",
37
+ "end"].join("\n")
38
+ end
39
+
40
+ create_file "config/initializers/cloudfront.rb" do
41
+ ["ActionController::Base.asset_host = ENV['CLOUDFRONT_URL']",
42
+ "config.public_file_server.headers = {",
43
+ " 'Cache-Control' => 'public, max-age=2592000',",
44
+ " \"Expires\" => \"\#{30.days.from_now.to_formatted_s(:rfc822)}\"",
45
+ " }"].join("\n")
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end
@@ -1,3 +1,3 @@
1
1
  module ThesisCloudfront
2
- VERSION = "0.2.0"
2
+ VERSION = "0.2.9"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: thesis_cloudfront
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nico Vigil
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-09-18 00:00:00.000000000 Z
11
+ date: 2019-12-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rack-cors
@@ -84,6 +84,7 @@ files:
84
84
  - bin/setup
85
85
  - lib/generators/thesis_cloudfront/install_generator.rb
86
86
  - lib/thesis_cloudfront.rb
87
+ - lib/thesis_cloudfront/install_generator.rb
87
88
  - lib/thesis_cloudfront/version.rb
88
89
  - thesis_cloudfront.gemspec
89
90
  homepage: https://github.com/nicovigil1/thesis_cloudfront