middleman / middleman-livereload

LiveReload support for Middleman
http://middlemanapp.com
MIT License
117 stars 37 forks source link

Livereload not working with asset-hashing enabled outside of the build-block #71

Open kasper opened 9 years ago

kasper commented 9 years ago

I can’t seem to get the latest livereload and Middleman to work on OS X 10.10.1 and Ruby 2.2.0. It sometimes states it’s listening for browsers to connect, sometimes not. However no updates are pushed to Safari. Reloading manually works fine.

File Gemfile

gem 'middleman', '3.3.7'
gem 'middleman-livereload', '3.4.2'

File config.rb

activate :livereload
middleman-site $ bundle exec middleman --verbose
== The Middleman is loading
== Activating: sprockets
== Reading:  Local config
== Activating: livereload
== Activating: directory_indexes
== Activating: asset_hash
== Activating: minify_css
== Activating: minify_javascript
Loaded extensions:
== Extension: sprockets
== Extension: livereload
== Extension: directory_indexes
== Extension: asset_hash
== Extension: minify_css
== Extension: minify_javascript
== Extension: frontmatter
== File Change: config.rb
== File Change: source/assets/stylesheets/style.css.scss
== File Change: source/index.html.haml
== File Change: source/layouts/layout.haml
== Rebuilding resource list
== LiveReload accepting connections from http://10.0.1.14:35729
[2015-01-22 18:27:15] INFO  WEBrick 1.3.1
[2015-01-22 18:27:15] INFO  ruby 2.2.0 (2014-12-25) [x86_64-darwin14]
== The Middleman is standing watch at http://0.0.0.0:4567
== Inspect your site configuration at http://0.0.0.0:4567/__middleman/
[2015-01-22 18:27:15] INFO  WEBrick::HTTPServer#start: pid=4117 port=4567
== Request: /
== Finishing Request: index.html (0.01s)
== File Change: source/index.html.haml
== Rebuilding resource list
LiveReload: File changed - source/index.html.haml
== LiveReloading path: /
^C[2015-01-22 18:28:10] INFO  going to shutdown ...
[2015-01-22 18:28:10] INFO  WEBrick::HTTPServer#start done.
== The Middleman is shutting down
Arcovion commented 9 years ago

Try activate :live_reload, host: '127.0.0.1', port: '4567'

kasper commented 9 years ago

@Arcovion Nope, doesn’t work.

middleman-site $ bundle exec middleman --verbose
== The Middleman is loading
== Activating: sprockets
== Reading:  Local config
== Activating: livereload
== Activating: directory_indexes
== Activating: asset_hash
== Activating: minify_css
== Activating: minify_javascript
Loaded extensions:
== Extension: sprockets
== Extension: livereload
== Extension: directory_indexes
== Extension: asset_hash
== Extension: minify_css
== Extension: minify_javascript
== Extension: frontmatter
== File Change: .rubocop.yml
== File Change: .ruby-version
== File Change: config.rb
== File Change: LICENSE.md
== File Change: README.md
== File Change: source/assets/images/.keep
== File Change: source/assets/javascripts/.keep
== File Change: source/assets/stylesheets/style.css.scss
== File Change: source/index.html.haml
== File Change: source/layouts/layout.haml
== Rebuilding resource list
== LiveReload accepting connections from http://127.0.0.1:4567
[2015-01-23 11:50:01] INFO  WEBrick 1.3.1
[2015-01-23 11:50:01] INFO  ruby 2.2.0 (2014-12-25) [x86_64-darwin14]
== The Middleman is standing watch at http://0.0.0.0:4567
== Inspect your site configuration at http://0.0.0.0:4567/__middleman/
[2015-01-23 11:50:01] INFO  WEBrick::HTTPServer#start: pid=838 port=4567
^C[2015-01-23 11:51:53] INFO  going to shutdown ...
[2015-01-23 11:51:53] INFO  WEBrick::HTTPServer#start done.
== The Middleman is shutting down

The server responds with an empty reply.

~ $ curl -v http://127.0.0.1:4567
* Rebuilt URL to: http://127.0.0.1:4567/
* Hostname was NOT found in DNS cache
*   Trying 127.0.0.1...
* Connected to 127.0.0.1 (127.0.0.1) port 4567 (#0)
> GET / HTTP/1.1
> User-Agent: curl/7.37.1
> Host: 127.0.0.1:4567
> Accept: */*
> 
* Empty reply from server
* Connection #0 to host 127.0.0.1 left intact
curl: (52) Empty reply from server

By the way, if I edit livereload settings while the server is running, I get an infinite loop of errors.

[2015-01-23 11:48:37] ERROR NoMethodError: undefined method `[]' for nil:NilClass
    /Users/Kasper/.rbenv/versions/2.2.0/lib/ruby/2.2.0/webrick/server.rb:174:in `block in start'

With the default settings, I’m not even seeing livereload.js injected into my Haml-templates. Shouldn’t it be?

Arcovion commented 9 years ago

Actually, leave off the port option - only change the host to 127.0.0.1. It should be injected on any html page with a tag, you can check for a response with this:

curl -v -H "Connection: Upgrade" -H "Upgrade: websocket" 127.0.0.1:35729
kasper commented 9 years ago

@Arcovion Ok. The WebSocket server is working with both the default settings and custom host. I can see curl connecting to Middleman as well. For some reason the livereload.js is not injected to the page.

middleman-site $ curl -v -H 'Connection: Upgrade' -H 'Upgrade: websocket' localhost:35729
* Rebuilt URL to: localhost:35729/
* Hostname was NOT found in DNS cache
*   Trying ::1...
* connect to ::1 port 35729 failed: Connection refused
*   Trying 127.0.0.1...
* Connected to localhost (127.0.0.1) port 35729 (#0)
> GET / HTTP/1.1
> User-Agent: curl/7.37.1
> Host: localhost:35729
> Accept: */*
> Connection: Upgrade
> Upgrade: websocket
> 
< HTTP/1.1 101 Web Socket Protocol Handshake
< Upgrade: WebSocket
< Connection: Upgrade
< WebSocket-Origin: 
< WebSocket-Location: ws://localhost:35729/
middleman-site $ curl -v -H 'Connection: Upgrade' -H 'Upgrade: websocket' 10.0.1.14:35729
* Rebuilt URL to: 10.0.1.14:35729/
* Hostname was NOT found in DNS cache
*   Trying 10.0.1.14...
* Connected to 10.0.1.14 (10.0.1.14) port 35729 (#0)
> GET / HTTP/1.1
> User-Agent: curl/7.37.1
> Host: 10.0.1.14:35729
> Accept: */*
> Connection: Upgrade
> Upgrade: websocket
> 
< HTTP/1.1 101 Web Socket Protocol Handshake
< Upgrade: WebSocket
< Connection: Upgrade
< WebSocket-Origin: 
< WebSocket-Location: ws://10.0.1.14:35729/
middleman-site $ curl -v http://localhost:4567
* Rebuilt URL to: http://localhost:4567/
* Hostname was NOT found in DNS cache
*   Trying ::1...
* connect to ::1 port 4567 failed: Connection refused
*   Trying 127.0.0.1...
* Connected to localhost (127.0.0.1) port 4567 (#0)
> GET / HTTP/1.1
> User-Agent: curl/7.37.1
> Host: localhost:4567
> Accept: */*
> 
< HTTP/1.1 200 OK 
< Content-Type: text/html; charset=utf-8
< Content-Length: 153
* Server WEBrick/1.3.1 (Ruby/2.2.0/2014-12-25) is not blacklisted
< Server: WEBrick/1.3.1 (Ruby/2.2.0/2014-12-25)
< Date: Fri, 23 Jan 2015 13:58:17 GMT
< Connection: Keep-Alive
< 
<!DOCTYPE html>
<html>
  <head>
    <meta charset='UTF-8'>
    <title>Hello World!</title>
  </head>
  <body>
    <p>Hello World!</p>
  </body>
</html>
* Connection #0 to host localhost left intact
Arcovion commented 9 years ago

Everything looks correct to me, could be a bug in the underlying rack-livereload middleware (which is what injects the Githubissues.

  • Githubissues is a development platform for aggregating issues.