ratalada-contrib 3.0.1 → 3.1.0

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: f94789e43bf70a8638e24126024e340669543cdb8126516faf70e4efb0ebb553
4
- data.tar.gz: 1e428b4d5dae6ed2dfc9ef06cc28d24bceb982f7255295d3918717e99a431881
3
+ metadata.gz: bfdfa2c6c7ee4b7dc67028882e3de270a3d4b54c32d540fc89ba8e7e0ba50ab5
4
+ data.tar.gz: ca771c956b1c2ee771f316e1e84d45d6d709154884d856059867fb7307693e38
5
5
  SHA512:
6
- metadata.gz: 7dfe78d482fbd3486981c591e50875219c0f2c1865c1cf7147547021a7a66aaeb535c9e1edeb1d09d85619047791d68805641bb577d2d62ea98267cf740b1669
7
- data.tar.gz: 4ca2093d272fc1e124d2c5f6697193206af316b53daf1113e57125b295877226250ecdefb2453a86013a62b8c108820e57d42a419e98e74ff38f2d99c7f5ce95
6
+ metadata.gz: 7a78f852ced399d457e904e3d2e3bd2b7c2a70083339b05b22d136042fb24f083436765cfe49365c3036f70dab830b793d7573c04bc3187fbbff92f34b2ee602
7
+ data.tar.gz: 6c6bdd43c7901c61198c1f83654af50e4a4dc100d6983659627f86fa61120545bbba63e13607e8dd7054e59d3dd0e656465c042b71eb530c9fdcb145cb50cceb
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "json"
4
+
5
+ module Ratalada
6
+ module Contrib
7
+ module Inertia
8
+ # The Inertia client posts JSON, which Sinatra does not read into `params`.
9
+ # This parses the body into the hash Rack::Request builds `params` from.
10
+ class JsonParamsMiddleware
11
+ def initialize(app) = @app = app
12
+
13
+ def call(env)
14
+ if env["CONTENT_TYPE"].to_s.start_with?("application/json")
15
+ body = env["rack.input"]&.read
16
+ env["rack.input"]&.rewind
17
+
18
+ begin
19
+ parsed = JSON.parse(body.to_s)
20
+ rescue JSON::ParserError
21
+ parsed = nil
22
+ end
23
+
24
+ if parsed.is_a?(Hash)
25
+ env["rack.request.form_hash"] = parsed
26
+ env["rack.request.form_input"] = env["rack.input"]
27
+ end
28
+ end
29
+
30
+ @app.call(env)
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
@@ -26,6 +26,7 @@ require_relative "inertia/core_ext"
26
26
  require_relative "inertia/response"
27
27
  require_relative "inertia/middleware"
28
28
  require_relative "inertia/csrf_middleware"
29
+ require_relative "inertia/json_params_middleware"
29
30
  require_relative "inertia/helpers"
30
31
 
31
32
  # LazyProp reports deprecation through code that's tied to rails.
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Ratalada
4
4
  module Contrib
5
- VERSION = "3.0.1"
5
+ VERSION = "3.1.0"
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ratalada-contrib
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.1
4
+ version: 3.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nathan K
@@ -53,6 +53,7 @@ files:
53
53
  - lib/ratalada/contrib/inertia/csrf_middleware.rb
54
54
  - lib/ratalada/contrib/inertia/errors.rb
55
55
  - lib/ratalada/contrib/inertia/helpers.rb
56
+ - lib/ratalada/contrib/inertia/json_params_middleware.rb
56
57
  - lib/ratalada/contrib/inertia/middleware.rb
57
58
  - lib/ratalada/contrib/inertia/response.rb
58
59
  - lib/ratalada/contrib/router/file_based.rb