Class: Hotwire::Livereload::Middleware
- Inherits:
-
Object
- Object
- Hotwire::Livereload::Middleware
- Defined in:
- lib/hotwire/livereload/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.
4 5 6 |
# File 'lib/hotwire/livereload/middleware.rb', line 4 def initialize(app) @app = app end |
Instance Method Details
#call(env) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/hotwire/livereload/middleware.rb', line 8 def call(env) request = ActionDispatch::Request.new(env) status, headers, response = @app.call(env) if html_response?(headers) body = get_response_body(response) if body&.include?("</head>") body = inject_livereload_scripts(body, request) headers["Content-Length"] = body.bytesize.to_s response = [body] end end [status, headers, response] end |