jets 1.5.2 → 1.5.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +3 -0
- data/Gemfile.lock +2 -2
- data/lib/jets/builders/code_builder.rb +12 -3
- data/lib/jets/builders/reconfigure_rails/config/initializers/jets.rb +3 -1
- data/lib/jets/builders/reconfigure_rails.rb +16 -1
- data/lib/jets/commands/help/build.md +2 -4
- data/lib/jets/controller/redirection.rb +1 -1
- data/lib/jets/controller/{renderers/template_renderer.rb → rendering/rack_renderer.rb} +101 -16
- data/lib/jets/controller/rendering.rb +4 -4
- data/lib/jets/version.rb +1 -1
- metadata +3 -6
- data/lib/jets/controller/renderers/base_renderer.rb +0 -12
- data/lib/jets/controller/renderers/rack_renderer.rb +0 -57
- data/lib/jets/controller/renderers.rb +0 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: acc1ca8f19a2a3312ebcd7d401233a81cd59a50332b12714efea1c7eb2630f70
|
4
|
+
data.tar.gz: 6c2dc27bca44f067688800db2bd02d0b9082996aa5fd6c4fdb59d677355f107e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9701f2ab97be26f14ff47b657717f6c973d183eb2d5de6342fa04bb79b1f01260c982aef592c33d4c897e8cfb4de8961d5d47b1bd05b55a1ffaae3cd578e9ffc
|
7
|
+
data.tar.gz: 2f15bff8efd7ea3ea3908704c526ad4c9f617be934caa77b2e3bdfee6e0ad5e99dcbd1dbf98fe6c621fb3259b5f5a7342213f044902e1762303a620d966f84f0
|
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.5.3]
|
7
|
+
- #142 from tongueroo/rails-api-afterburner fix jets afterburner for rails api mode apps
|
8
|
+
|
6
9
|
## [1.5.2]
|
7
10
|
- #138 from patchkit-net/feature/before_action_chain_break Change before_action behavior: allow chain break
|
8
11
|
- #139 from patchkit-net/bugfix/spec-gem-files-dir Fix jets.gemspec files listing method
|
data/Gemfile.lock
CHANGED
@@ -11,7 +11,7 @@ GIT
|
|
11
11
|
PATH
|
12
12
|
remote: .
|
13
13
|
specs:
|
14
|
-
jets (1.5.
|
14
|
+
jets (1.5.3)
|
15
15
|
activerecord (>= 5.2.1)
|
16
16
|
activesupport (>= 5.2.1)
|
17
17
|
aws-sdk-apigateway
|
@@ -131,7 +131,7 @@ GEM
|
|
131
131
|
mini_portile2 (2.4.0)
|
132
132
|
minitest (5.11.3)
|
133
133
|
mysql2 (0.5.2)
|
134
|
-
nokogiri (1.10.
|
134
|
+
nokogiri (1.10.1)
|
135
135
|
mini_portile2 (~> 2.4.0)
|
136
136
|
rack (2.0.6)
|
137
137
|
rack-proxy (0.6.5)
|
@@ -201,15 +201,13 @@ class Jets::Builders
|
|
201
201
|
# This happens in the current app directory not the tmp code for simplicity
|
202
202
|
# This is because the node likely been set up correctly there.
|
203
203
|
def compile_rails_assets
|
204
|
-
return unless rails?
|
204
|
+
return unless Jets.rack? && rails? && !rails_api?
|
205
205
|
|
206
206
|
if ENV['JETS_SKIP_ASSETS']
|
207
207
|
puts "Skip compiling rack assets".colorize(:yellow) # useful for debugging
|
208
208
|
return
|
209
209
|
end
|
210
210
|
|
211
|
-
return unless Jets.rack?
|
212
|
-
|
213
211
|
# Need to capture JETS_ROOT since can be changed by Turbo mode
|
214
212
|
jets_root = Jets.root
|
215
213
|
Bundler.with_clean_env do
|
@@ -232,12 +230,23 @@ class Jets::Builders
|
|
232
230
|
end
|
233
231
|
|
234
232
|
# Rudimentary rails detection
|
233
|
+
# Duplicated in builders/reconfigure_rails.rb
|
235
234
|
def rails?
|
236
235
|
config_ru = "#{Jets.root}rack/config.ru"
|
237
236
|
return false unless File.exist?(config_ru)
|
238
237
|
!IO.readlines(config_ru).grep(/Rails.application/).empty?
|
239
238
|
end
|
240
239
|
|
240
|
+
# Rudimentary rails api detection
|
241
|
+
# Duplicated in builders/reconfigure_rails.rb
|
242
|
+
# Another way of checking is loading a rails console and checking Rails.application.config.api_only
|
243
|
+
# Using this way for simplicity.
|
244
|
+
def rails_api?
|
245
|
+
config_app = "#{Jets.root}rack/config/application.rb"
|
246
|
+
return false unless File.exist?(config_app)
|
247
|
+
!IO.readlines(config_app).grep(/config.api_only.*=.*true/).empty?
|
248
|
+
end
|
249
|
+
|
241
250
|
# Cleans out non-cached files like code-*.zip in Jets.build_root
|
242
251
|
# for a clean start. Also ensure that the /tmp/jets/project build root exists.
|
243
252
|
#
|
@@ -4,11 +4,13 @@ JetsRails.stage = ENV['JETS_STAGE'] || 'dev' # for jets-rails StageMiddleware
|
|
4
4
|
s3_base_url = IO.read("#{Rails.root}/config/s3_base_url.txt").strip rescue "s3_base_url_placeholder"
|
5
5
|
asset_host = "#{s3_base_url}/rack/public"
|
6
6
|
Rails.application.config.action_controller.asset_host = asset_host
|
7
|
+
Rails.application.config.public_file_server.enabled = true
|
7
8
|
|
9
|
+
<% unless @api_mode -%>
|
8
10
|
# Rails.application.config.assets.quiet = false
|
9
11
|
Rails.application.config.assets.debug = false
|
10
12
|
Rails.application.config.assets.compile = false
|
11
|
-
|
13
|
+
<% end -%>
|
12
14
|
|
13
15
|
# Looks better without colorizatiion in CloudWatch logs
|
14
16
|
Rails.application.config.colorize_logging = false
|
@@ -22,9 +22,13 @@ class Jets::Builders
|
|
22
22
|
templates = File.expand_path("./reconfigure_rails", File.dirname(__FILE__))
|
23
23
|
relative_path = "config/initializers/jets.rb"
|
24
24
|
src = "#{templates}/#{relative_path}"
|
25
|
+
result = Jets::Erb.result(src, api_mode: rails_api?)
|
25
26
|
dest = "#{@app_root}/#{relative_path}"
|
26
27
|
FileUtils.mkdir_p(File.dirname(dest))
|
27
|
-
|
28
|
+
IO.write(dest, result)
|
29
|
+
end
|
30
|
+
|
31
|
+
def api_mode?
|
28
32
|
end
|
29
33
|
|
30
34
|
def update_gemfile
|
@@ -90,10 +94,21 @@ class Jets::Builders
|
|
90
94
|
end
|
91
95
|
|
92
96
|
# Rudimentary rails detection
|
97
|
+
# Duplicated in builders/code_builders.rb
|
93
98
|
def rails?
|
94
99
|
config_ru = "#{@app_root}/config.ru"
|
95
100
|
return false unless File.exist?(config_ru)
|
96
101
|
!IO.readlines(config_ru).grep(/Rails.application/).empty?
|
97
102
|
end
|
103
|
+
|
104
|
+
# Rudimentary rails api detection
|
105
|
+
# Duplicated in builders/code_builders.rb
|
106
|
+
# Another way of checking is loading a rails console and checking Rails.application.config.api_only
|
107
|
+
# Using this way for simplicity.
|
108
|
+
def rails_api?
|
109
|
+
config_app = "#{@app_root}/config/application.rb"
|
110
|
+
return false unless File.exist?(config_app)
|
111
|
+
!IO.readlines(config_app).grep(/config.api_only.*=.*true/).empty?
|
112
|
+
end
|
98
113
|
end
|
99
114
|
end
|
@@ -1,8 +1,6 @@
|
|
1
1
|
Builds a zip file package to be uploaded to AWS Lambda. This allows you to build the project without deploying and inspect the zip file that gets deployed to AWS Lambda. The package contains:
|
2
2
|
|
3
3
|
* your application code
|
4
|
-
* generated
|
5
|
-
* bundled gems
|
6
|
-
* bundled Ruby
|
4
|
+
* generated shims
|
7
5
|
|
8
|
-
If the application has no
|
6
|
+
If the application has no Ruby code and only uses Polymorphic functions, then gems are not bundled up.
|
@@ -19,7 +19,7 @@ class Jets::Controller
|
|
19
19
|
|
20
20
|
redirect_url = ensure_protocol(redirect_url)
|
21
21
|
|
22
|
-
aws_proxy =
|
22
|
+
aws_proxy = Rendering::RackRenderer.new(self,
|
23
23
|
status: options[:status] || 302,
|
24
24
|
headers: { "Location" => redirect_url },
|
25
25
|
body: "",
|
@@ -1,22 +1,42 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
1
|
+
require "rack/utils"
|
2
|
+
|
3
|
+
# Special renderer. All the other renderers lead here
|
4
|
+
module Jets::Controller::Rendering
|
5
|
+
class RackRenderer
|
6
|
+
delegate :request, :event, :headers, to: :controller
|
7
|
+
attr_reader :controller
|
8
|
+
def initialize(controller, options={})
|
9
|
+
@controller = controller
|
10
|
+
@options = options
|
11
11
|
end
|
12
12
|
|
13
|
+
# Example response:
|
14
|
+
#
|
15
|
+
# [200, {"my-header" = > "value" }, "my body" ]
|
16
|
+
#
|
17
|
+
# Returns rack triplet
|
13
18
|
def render
|
19
|
+
# we do some normalization here
|
20
|
+
status = normalize_status_code(@options[:status])
|
21
|
+
|
22
|
+
base64 = normalized_base64_option(@options)
|
23
|
+
|
24
|
+
headers = @options[:headers] || {}
|
25
|
+
headers = cors_headers.merge(headers)
|
26
|
+
set_content_type!(status, headers)
|
27
|
+
# x-jets-base64 to convert this Rack triplet to a API Gateway hash structure later
|
28
|
+
headers["x-jets-base64"] = base64 ? 'yes' : 'no' # headers values must be Strings
|
29
|
+
|
14
30
|
# Rails rendering does heavy lifting
|
15
|
-
|
16
|
-
|
17
|
-
|
31
|
+
if drop_content_info?(status)
|
32
|
+
body = StringIO.new
|
33
|
+
else
|
34
|
+
renderer = ActionController::Base.renderer.new(renderer_options)
|
35
|
+
body = renderer.render(render_options)
|
36
|
+
body = StringIO.new(body)
|
37
|
+
end
|
18
38
|
|
19
|
-
|
39
|
+
[status, headers, body] # triplet
|
20
40
|
end
|
21
41
|
|
22
42
|
# Example: posts/index
|
@@ -114,6 +134,72 @@ module Jets::Controller::Renderers
|
|
114
134
|
render_options
|
115
135
|
end
|
116
136
|
|
137
|
+
def controller_instance_variables
|
138
|
+
instance_vars = @controller.instance_variables.inject({}) do |vars, v|
|
139
|
+
k = v.to_s.sub(/^@/,'') # @var => var
|
140
|
+
vars[k] = @controller.instance_variable_get(v)
|
141
|
+
vars
|
142
|
+
end
|
143
|
+
instance_vars[:event] = event
|
144
|
+
instance_vars
|
145
|
+
end
|
146
|
+
|
147
|
+
private
|
148
|
+
# From jets/controller/response.rb
|
149
|
+
def drop_content_info?(status)
|
150
|
+
status.to_i / 100 == 1 or drop_body?(status)
|
151
|
+
end
|
152
|
+
|
153
|
+
DROP_BODY_RESPONSES = [204, 304]
|
154
|
+
def drop_body?(status)
|
155
|
+
DROP_BODY_RESPONSES.include?(status.to_i)
|
156
|
+
end
|
157
|
+
|
158
|
+
# maps:
|
159
|
+
# :continue => 100
|
160
|
+
# :success => 200
|
161
|
+
# etc
|
162
|
+
def normalize_status_code(code)
|
163
|
+
status_code = if code.is_a?(Symbol)
|
164
|
+
Rack::Utils::SYMBOL_TO_STATUS_CODE[code]
|
165
|
+
else
|
166
|
+
code
|
167
|
+
end
|
168
|
+
(status_code || 200).to_s # API Gateway requires a string but rack is okay with either
|
169
|
+
end
|
170
|
+
|
171
|
+
def set_content_type!(status, headers)
|
172
|
+
if drop_content_info?(status)
|
173
|
+
headers.delete "Content-Length"
|
174
|
+
headers.delete "Content-Type"
|
175
|
+
else
|
176
|
+
headers["Content-Type"] = @options[:content_type] ||
|
177
|
+
headers['content-type'] || # Mega Mode (Rails)
|
178
|
+
headers['Content-Type'] || # Just in case
|
179
|
+
Jets::Controller::DEFAULT_CONTENT_TYPE
|
180
|
+
end
|
181
|
+
end
|
182
|
+
|
183
|
+
def normalized_base64_option(options)
|
184
|
+
base64 = @options[:base64] if options.key?(:base64)
|
185
|
+
base64 = @options[:isBase64Encoded] if options.key?(:isBase64Encoded)
|
186
|
+
base64
|
187
|
+
end
|
188
|
+
|
189
|
+
def cors_headers
|
190
|
+
case Jets.config.cors
|
191
|
+
when true
|
192
|
+
{
|
193
|
+
"Access-Control-Allow-Origin" => "*", # Required for CORS support to work
|
194
|
+
"Access-Control-Allow-Credentials" => "true" # Required for cookies, authorization headers with HTTPS
|
195
|
+
}
|
196
|
+
when Hash
|
197
|
+
Jets.config.cors # contains Hash with Access-Control-Allow-* values
|
198
|
+
else
|
199
|
+
{}
|
200
|
+
end
|
201
|
+
end
|
202
|
+
|
117
203
|
class << self
|
118
204
|
def setup!
|
119
205
|
require "action_controller"
|
@@ -161,8 +247,7 @@ module Jets::Controller::Renderers
|
|
161
247
|
end
|
162
248
|
end
|
163
249
|
end
|
164
|
-
|
165
250
|
end
|
166
251
|
end
|
167
252
|
|
168
|
-
Jets::Controller::
|
253
|
+
Jets::Controller::Rendering::RackRenderer.setup!
|
@@ -1,14 +1,13 @@
|
|
1
1
|
class Jets::Controller
|
2
|
-
autoload :Renderers, "jets/controller/renderers"
|
3
|
-
|
4
2
|
module Rendering
|
3
|
+
autoload :RackRenderer, "jets/controller/rendering/rack_renderer"
|
5
4
|
include Redirection
|
6
5
|
|
7
6
|
def ensure_render
|
8
7
|
return @rendered_data if @rendered
|
9
8
|
|
10
9
|
# defaults to rendering templates
|
11
|
-
|
10
|
+
RackRenderer.new(self, managed_options).render
|
12
11
|
end
|
13
12
|
|
14
13
|
# Many different ways to render:
|
@@ -27,7 +26,8 @@ class Jets::Controller
|
|
27
26
|
|
28
27
|
options.reverse_merge!(managed_options)
|
29
28
|
adjust_content_type!(options)
|
30
|
-
|
29
|
+
|
30
|
+
@rendered_data = RackRenderer.new(self, options).render
|
31
31
|
|
32
32
|
@rendered = true
|
33
33
|
@rendered_data
|
data/lib/jets/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jets
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.5.
|
4
|
+
version: 1.5.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tung Nguyen
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-01-
|
11
|
+
date: 2019-01-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -619,11 +619,8 @@ files:
|
|
619
619
|
- lib/jets/controller/rack/adapter.rb
|
620
620
|
- lib/jets/controller/rack/env.rb
|
621
621
|
- lib/jets/controller/redirection.rb
|
622
|
-
- lib/jets/controller/renderers.rb
|
623
|
-
- lib/jets/controller/renderers/base_renderer.rb
|
624
|
-
- lib/jets/controller/renderers/rack_renderer.rb
|
625
|
-
- lib/jets/controller/renderers/template_renderer.rb
|
626
622
|
- lib/jets/controller/rendering.rb
|
623
|
+
- lib/jets/controller/rendering/rack_renderer.rb
|
627
624
|
- lib/jets/controller/request.rb
|
628
625
|
- lib/jets/controller/response.rb
|
629
626
|
- lib/jets/core.rb
|
@@ -1,12 +0,0 @@
|
|
1
|
-
# Interface:
|
2
|
-
# subclasses must implement render
|
3
|
-
module Jets::Controller::Renderers
|
4
|
-
class BaseRenderer
|
5
|
-
delegate :request, :event, :headers, to: :controller
|
6
|
-
attr_reader :controller
|
7
|
-
def initialize(controller, options={})
|
8
|
-
@controller = controller
|
9
|
-
@options = options
|
10
|
-
end
|
11
|
-
end
|
12
|
-
end
|
@@ -1,57 +0,0 @@
|
|
1
|
-
require "rack/utils"
|
2
|
-
|
3
|
-
# Special renderer. All the other renderers lead here
|
4
|
-
module Jets::Controller::Renderers
|
5
|
-
class RackRenderer < BaseRenderer
|
6
|
-
# Example response:
|
7
|
-
#
|
8
|
-
# [200, {"my-header" = > "value" }, "my body" ]
|
9
|
-
def render
|
10
|
-
# we do some normalization here
|
11
|
-
status = map_status_code(@options[:status]) || 200
|
12
|
-
status = status.to_s # API Gateway requires a string but rack is okay with either
|
13
|
-
body = @options[:body]
|
14
|
-
base64 = normalized_base64_option(@options)
|
15
|
-
|
16
|
-
headers = @options[:headers] || {}
|
17
|
-
headers = cors_headers.merge(headers)
|
18
|
-
headers["Content-Type"] ||= @options[:content_type] || Jets::Controller::DEFAULT_CONTENT_TYPE
|
19
|
-
# x-jets-base64 to convert this Rack triplet to a API Gateway hash structure later
|
20
|
-
headers["x-jets-base64"] = base64 ? 'yes' : 'no' # headers values must be Strings
|
21
|
-
body = StringIO.new(body)
|
22
|
-
[status, headers, body] # triplet
|
23
|
-
end
|
24
|
-
|
25
|
-
# maps:
|
26
|
-
# :continue => 100
|
27
|
-
# :success => 200
|
28
|
-
# etc
|
29
|
-
def map_status_code(code)
|
30
|
-
if code.is_a?(Symbol)
|
31
|
-
Rack::Utils::SYMBOL_TO_STATUS_CODE[code]
|
32
|
-
else
|
33
|
-
code
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
def normalized_base64_option(options)
|
38
|
-
base64 = @options[:base64] if options.key?(:base64)
|
39
|
-
base64 = @options[:isBase64Encoded] if options.key?(:isBase64Encoded)
|
40
|
-
base64
|
41
|
-
end
|
42
|
-
|
43
|
-
def cors_headers
|
44
|
-
case Jets.config.cors
|
45
|
-
when true
|
46
|
-
{
|
47
|
-
"Access-Control-Allow-Origin" => "*", # Required for CORS support to work
|
48
|
-
"Access-Control-Allow-Credentials" => "true" # Required for cookies, authorization headers with HTTPS
|
49
|
-
}
|
50
|
-
when Hash
|
51
|
-
Jets.config.cors # contains Hash with Access-Control-Allow-* values
|
52
|
-
else
|
53
|
-
{}
|
54
|
-
end
|
55
|
-
end
|
56
|
-
end
|
57
|
-
end
|