jets 1.0.7 → 1.0.8

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: 5da9ac08bb004e01baf04e9492edef4529f228f0005d35d16680108b549596cf
4
- data.tar.gz: 8989aaae567491f3eb9aaa82a89c8baaa06ef937fe4efb01f08e670c8a4573e4
3
+ metadata.gz: 0ebbd9b1b776aec34e0e527bcd9734ff6df36079046182b9f6e5e284dd039379
4
+ data.tar.gz: 60fa104f233b42bf6dad52d49bb7da8d437c4b12da7ba902db3203bdf606c5a1
5
5
  SHA512:
6
- metadata.gz: 258f55e1c7b1efaa7a89905f93cc37af964e42aa3dd5d87bdfb42d71c02dd84d563bab15927a9563b090090f44053f43626c576adf1962db5f1795486c209a14
7
- data.tar.gz: c761939a1ba8e5b55b2d96b0653fad00d60bfecd16769f5f4fa716363f1324eaa71a2c6ff8d9442e53ed193f47bc8b483a45275e1862f258edbb2dfe85e20c32
6
+ metadata.gz: c45452bfcd0e51876a95f3916cd50bae63d3337ed9c0766f83d96be811ed3a33fc1e783f83f2d7015694aeba2ffe22be60758a8265513b88ecce5587f675cbff
7
+ data.tar.gz: b0cc8b3a8d59a1df3e1cfb94762721922b5cd6dfdb77ced858600d22360f874299f442341cd4a21fd0b01c2c853fec6a3bf62b950beb23642ac694ec694cbe44
data/CHANGELOG.md CHANGED
@@ -3,6 +3,9 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  This project *loosely tries* to adhere to [Semantic Versioning](http://semver.org/), even before v1.0.
5
5
 
6
+ ## [1.0.8]
7
+ - fix s3 assets to work with custom domains #58 from tongueroo/fix-assets
8
+
6
9
  ## [1.0.7]
7
10
  - jets new: adjust skeleton template project
8
11
  - jets import:rails: update config/database.yml
data/Gemfile.lock CHANGED
@@ -11,7 +11,7 @@ GIT
11
11
  PATH
12
12
  remote: .
13
13
  specs:
14
- jets (1.0.7)
14
+ jets (1.0.8)
15
15
  actionpack (>= 5.2.1)
16
16
  actionview (>= 5.2.1)
17
17
  activerecord (>= 5.2.1)
data/README.md CHANGED
@@ -132,7 +132,7 @@ Here's a [Live Demo](https://demo.rubyonjets.com/posts) of the quintessential CR
132
132
 
133
133
  ### Rails Support
134
134
 
135
- Jets [Mega Mode](http://rubyonjets.com/docs/megamode/) provides Rails support with little effort. This allows you to run a Rails application on AWS Lambda. Refer to the [Rails Support](http://rubyonjets.com/docs/rails-support/) docs for more info.
135
+ Jets [Mega Mode](http://rubyonjets.com/docs/megamode/) provides Rails support with little effort. This allows you to run a Rails application on AWS Lambda. Refer to the [Rails Support](http://rubyonjets.com/docs/rails-support/) docs for more info. Also here's a Tutorial Blog Post on Mega Mode: [Run Rails on AWS Lambda](https://blog.boltops.com/2018/11/03/jets-mega-mode-run-rails-on-aws-lambda).
136
136
 
137
137
  ### More Info
138
138
 
@@ -8,7 +8,7 @@
8
8
  <title>Jets App</title>
9
9
  <%%= javascript_pack_tag "application" %>
10
10
  <%%= stylesheet_pack_tag "theme" %>
11
- <link rel="shortcut icon" href="<%%= asset_path("/favicon.ico") %>">
11
+ <link rel="shortcut icon" href="<%%= favicon_path %>">
12
12
  </head>
13
13
  <body>
14
14
  <section class="starter">
@@ -32,21 +32,64 @@ module Jets::Controller::Renderers
32
32
  # default options:
33
33
  # https://github.com/rails/rails/blob/master/actionpack/lib/action_controller/renderer.rb#L41-L47
34
34
  def renderer_options
35
+ options = {
36
+ # script_name: "", # unfortunately doesnt seem to effect relative_url_root like desired
37
+ # input: ""
38
+ }
39
+
35
40
  origin = headers["origin"]
36
41
  if origin
37
42
  uri = URI.parse(origin)
38
- https = uri.scheme == "https"
43
+ options[:https] = uri.scheme == "https"
39
44
  end
40
- options = {
41
- http_host: headers["host"],
42
- https: https,
43
- # script_name: "",
44
- # input: ""
45
- }
45
+
46
+ # Important to not use rack_headers as local variable instead of headers.
47
+ # headers is a method that gets deleted to controller.headers and using it
48
+ # seems to cause issues.
49
+ rack_headers = rackify_headers(headers)
50
+ options.merge!(rack_headers)
51
+
52
+ # Note @options[:method] uses @options vs options on purpose
46
53
  @options[:method] = event["httpMethod"].downcase if event["httpMethod"]
47
54
  options
48
55
  end
49
56
 
57
+ # Takes headers and adds HTTP_ to front of the keys because that is what rack
58
+ # does to the headers passed from a request. This seems to be the standard
59
+ # when testing with curl and inspecting the headers in a Rack app. Example:
60
+ # https://gist.github.com/tongueroo/94f22f6c261c8999e4f4f776547e2ee3
61
+ #
62
+ # This is useful for:
63
+ #
64
+ # ActionController::Base.renderer.new(renderer_options)
65
+ #
66
+ # renderer_options are rack normalized headers.
67
+ #
68
+ # Example input (from api gateway)
69
+ #
70
+ # {"host"=>"localhost:8888",
71
+ # "user-agent"=>"curl/7.53.1",
72
+ # "accept"=>"*/*",
73
+ # "version"=>"HTTP/1.1",
74
+ # "x-amzn-trace-id"=>"Root=1-5bde5b19-61d0d4ab4659144f8f69e38f"}
75
+ #
76
+ # Example output:
77
+ #
78
+ # {"HTTP_HOST"=>"localhost:8888",
79
+ # "HTTP_USER_AGENT"=>"curl/7.53.1",
80
+ # "HTTP_ACCEPT"=>"*/*",
81
+ # "HTTP_VERSION"=>"HTTP/1.1",
82
+ # "HTTP_X_AMZN_TRACE_ID"=>"Root=1-5bde5b19-61d0d4ab4659144f8f69e38f"}
83
+ #
84
+ def rackify_headers(headers)
85
+ results = {}
86
+ headers.each do |k,v|
87
+ rack_key = 'HTTP_' + k.gsub('-','_').upcase
88
+ results[rack_key] = v
89
+ end
90
+ results
91
+ end
92
+
50
93
  def render_options
51
94
  # nomralize the template option
52
95
  template = @options[:template]
@@ -25,7 +25,7 @@ module Jets::AssetTagHelper
25
25
  def image_tag(source, options = {})
26
26
  # mimic original behavior to get /images in source
27
27
  source = "/images/#{source}" unless source.starts_with?('/')
28
- if on_aws?(source)
28
+ if on_aws?
29
29
  source = "#{s3_public}#{source}"
30
30
  end
31
31
 
@@ -33,7 +33,7 @@ module Jets::AssetTagHelper
33
33
  end
34
34
 
35
35
  def asset_path(source, options = {})
36
- if on_aws?(source) && asset_folder?(source)
36
+ if on_aws? && asset_folder?(source)
37
37
  # mimic original behavior to get /images in source
38
38
  source = "/images/#{source}" unless source.starts_with?('/')
39
39
  source = "#{s3_public}#{source}"
@@ -42,6 +42,15 @@ module Jets::AssetTagHelper
42
42
  super
43
43
  end
44
44
 
45
+ # Serves favicon out of s3 when on API gateway.
46
+ #
47
+ # Useful helper for API Gateway since serving binary data like images without
48
+ # an Accept header doesnt work well. You can changed Media Types to '*/*'
49
+ # but then that messes up form data.
50
+ def favicon_path(path='favicon.ico')
51
+ on_aws? ? "#{s3_public}/#{path}" : "/#{path}"
52
+ end
53
+
45
54
  private
46
55
  # Whatever is configured in Jets.config.assets.folders
47
56
  # Example: packs, images, assets
@@ -80,7 +89,7 @@ private
80
89
  # Url: /packs/application-e7654c50abd78161b641.js
81
90
  # Returns: https://s3-us-west-2.amazonaws.com/demo-dev-s3bucket-1jg5o076egkk4/jets/public/packs/application-e7654c50abd78161b641.js
82
91
  def add_s3_public(url)
83
- return url unless on_aws?(url)
92
+ return url unless on_aws?
84
93
  "#{s3_public}#{url}"
85
94
  end
86
95
 
@@ -1,13 +1,20 @@
1
1
  module Jets::CommonMethods
2
+ extend Memoist
2
3
  # Add API Gateway Stage Name
3
4
  def add_stage_name(url)
4
- return url unless on_aws?(url)
5
+ return url unless add_stage?(url)
5
6
 
6
7
  stage_name = Jets::Resource::ApiGateway::Deployment.stage_name
7
8
  "/#{stage_name}#{url}"
8
9
  end
9
10
 
10
- def on_aws?(url)
11
+ def add_stage?(url)
11
12
  request.host.include?("amazonaws.com") && url.starts_with?('/')
12
13
  end
14
+ memoize :add_stage?
15
+
16
+ def on_aws?
17
+ !request.headers['HTTP_X_AMZN_TRACE_ID'].nil?
18
+ end
19
+ memoize :on_aws?
13
20
  end
@@ -79,6 +79,11 @@ class Jets::Server
79
79
  end
80
80
  end
81
81
 
82
+ # Way to fake X-Amzn-Trace-Id which on_aws? helper checks
83
+ if ENV['JETS_ON_AWS']
84
+ headers["X-Amzn-Trace-Id"] = "Root=fake-trace-id"
85
+ end
86
+
82
87
  # There are also a couple of other headers that are specific to
83
88
  # AWS Lambda Proxy and API Gateway. Example:
84
89
  #
data/lib/jets/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Jets
2
- VERSION = "1.0.7"
2
+ VERSION = "1.0.8"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jets
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.7
4
+ version: 1.0.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tung Nguyen