Class: LiveComponent::Middleware
- Inherits:
-
Object
- Object
- LiveComponent::Middleware
- Defined in:
- lib/live_component/middleware.rb
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app) ⇒ Middleware
constructor
A new instance of Middleware.
Constructor Details
#initialize(app) ⇒ Middleware
Returns a new instance of Middleware.
7 8 9 |
# File 'lib/live_component/middleware.rb', line 7 def initialize(app) @app = app end |
Instance Method Details
#call(env) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/live_component/middleware.rb', line 11 def call(env) if env["PATH_INFO"] == "/live_component/render" raw_data = env["rack.input"].read data = JSON.parse(raw_data) payload, compressed = LiveComponent::Payload.decode(data["payload"]) result = LiveComponent::RenderController.renderer.render( :show, assigns: { state: payload["state"], reflexes: payload["reflexes"] }, layout: false ) result = LiveComponent::Payload.encode(result, compress: compressed) return [200, { "Content-Type" => "text/html" }, [result]] end @app.call(env) end |