johnbintz / rack-livereload Goto Github PK
View Code? Open in Web Editor NEWhttps://github.com/onesupercoder/rack-livereload
License: MIT License
https://github.com/onesupercoder/rack-livereload
License: MIT License
thanks for all your work on it.
I've followed, so I believe, the straight guidance on getting live reload working, but
the script tag isn't being injected in the head tag. My project is at https://github.com/aedenj/insight.
I'm sure you could automatically ignore anything with Content-Type
matching text/event-stream
.
The bit I got stuck on trying to get ssl working for our Rails/nginx setup was that the protocol is hard-coded to ws://
in livereload.js. Changing that to wss
allowed me to set up the right ssl proxy in nginx to guard.
Using
config.middleware.use Rack::LiveReload
positions the middleware after ActiveRecord::SessionStore
.
This is a problem when in development you use flash.keep
since requests for livereload assets will go through the session store and thus void the use of flash.keep
. Instead, using the following works much better:
config.middleware.insert_after ActionDispatch::Static, Rack::LiveReload
Not only will your session store not be touched, but you also save yourself some logging verbosity by not logging the GET requests for livereload's static assets.
I'll try to make a PR for the README soon.
This is really great stuff, but sadly it doesn't work for me in Firefox and Chrome, only Safari does. Any idea what could be the problem? I use all the newest versions of Rails, browsers, gems, etc.
Hello!
I'm trying to change the default host from localhost
to livereload
but it seems that rack-livereload is not seeing my changes. However! I'm totally able to modify the livereload port, just the host modification is broken.
Puma caught this error: Failed to open TCP connection to localhost:1234 (Cannot assign requested address - connect(2) for "localhost" port 1234) (Errno::EADDRNOTAVAIL)
/usr/local/lib/ruby/2.4.0/net/http.rb:906:in `rescue in block in connect'
/usr/local/lib/ruby/2.4.0/net/http.rb:903:in `block in connect'
/usr/local/lib/ruby/2.4.0/timeout.rb:93:in `block in timeout'
/usr/local/lib/ruby/2.4.0/timeout.rb:103:in `timeout'
/usr/local/lib/ruby/2.4.0/net/http.rb:902:in `connect'
/usr/local/lib/ruby/2.4.0/net/http.rb:887:in `do_start'
/usr/local/lib/ruby/2.4.0/net/http.rb:876:in `start'
/usr/local/lib/ruby/2.4.0/net/http.rb:1407:in `request'
/box/gems/rack-mini-profiler-0.10.5/lib/patches/net_patches.rb:7:in `block in request_with_mini_profiler'
/box/gems/rack-mini-profiler-0.10.5/lib/mini_profiler/profiling_methods.rb:31:in `step'
/box/gems/rack-mini-profiler-0.10.5/lib/patches/net_patches.rb:6:in `request_with_mini_profiler'
/usr/local/lib/ruby/2.4.0/net/http.rb:1387:in `send_request'
/box/gems/rack-livereload-0.3.16/lib/rack/livereload/body_processor.rb:50:in `use_vendored?'
/box/gems/rack-livereload-0.3.16/lib/rack/livereload/body_processor.rb:101:in `livereload_source'
(erb):14:in `block (2 levels) in process!'
/usr/local/lib/ruby/2.4.0/erb.rb:896:in `eval'
/usr/local/lib/ruby/2.4.0/erb.rb:896:in `result'
/box/gems/rack-livereload-0.3.16/lib/rack/livereload/body_processor.rb:78:in `block (2 levels) in process!'
/box/gems/activesupport-5.0.5/lib/active_support/core_ext/string/output_safety.rb:237:in `gsub!'
/box/gems/activesupport-5.0.5/lib/active_support/core_ext/string/output_safety.rb:237:in `gsub!'
/box/gems/rack-livereload-0.3.16/lib/rack/livereload/body_processor.rb:78:in `block in process!'
/box/gems/rack-livereload-0.3.16/lib/rack/livereload/body_processor.rb:76:in `each'
/box/gems/rack-livereload-0.3.16/lib/rack/livereload/body_processor.rb:76:in `process!'
/box/gems/rack-livereload-0.3.16/lib/rack/livereload.rb:28:in `_call'
/box/gems/rack-livereload-0.3.16/lib/rack/livereload.rb:14:in `call'
/box/gems/actionpack-5.0.5/lib/action_dispatch/middleware/static.rb:136:in `call'
/box/gems/rack-2.0.3/lib/rack/sendfile.rb:111:in `call'
/box/gems/rack-mini-profiler-0.10.5/lib/mini_profiler/profiler.rb:282:in `call'
/box/gems/railties-5.0.5/lib/rails/engine.rb:522:in `call'
/box/gems/puma-3.9.1/lib/puma/configuration.rb:224:in `call'
/box/gems/puma-3.9.1/lib/puma/server.rb:602:in `handle_request'
/box/gems/puma-3.9.1/lib/puma/server.rb:435:in `process_client'
/box/gems/puma-3.9.1/lib/puma/server.rb:299:in `block in run'
/box/gems/puma-3.9.1/lib/puma/thread_pool.rb:120:in `block in spawn_thread'
And my config:
# ...
config.middleware.insert_after ActionDispatch::Static, Rack::LiveReload
config.middleware.use(Rack::LiveReload,
:min_delay => 500, # default 1000
:max_delay => 10_000, # default 60_000
:live_reload_port => 1234, # default 35729
:host => 'livereload',
:ignore => [ %r{dont/modify\.html$} ]
)
# ...
Since it's becoming a giant blob of if
statements.
I am using Padrino and can't get the script tag to be injected.
The app can be found at https://github.com/leebrooks0/padrino_template,
but here is my config.ru
#!/usr/bin/env rackup
# encoding: utf-8
# This file can be used to start Padrino,
# just execute it from the command line.
require File.expand_path("../config/boot.rb", __FILE__)
require 'rack-livereload'
Padrino::Application.use Rack::LiveReload
run Padrino.application
Please consider embedding the LiveReload script the way LiveReload app itself advises:
<script>document.write('<script src="http://' + (location.host || 'localhost').split(':')[0] + ':35729/livereload.js?snipver=1"></' + 'script>')</script>
Currently Rack embeds the script with a hard 0.0.0.0 IP address, and this doesn't work when testing with mobile devices over my WiFi network (because mobile devices browse to my Mac's network IP, not 0.0.0.0).
Merely specifying an IP in config.rb isn't optimal because my Mac's IP changes depending on whether I'm home or at work.
I'm getting an error from Rack::Lint:
ERROR Rack::Lint::LintError: Content-Length header was 599, but should be 261
My simple rackup file contains:
require 'rubygems'
require 'bundler/setup'
require 'rack-livereload'
use Rack::LiveReload
run Rack::Directory.new('.')
What I'm doing wrong? Do I misunderstand the middleware concept?
So I want to run SSL in development. This poses a challenge because an SSL-enabled page will not accept non-ssl javascript.
So naturally rack-livereload needs to run in ssl mode. But of course I don't expect you guys to write an SSL server. So NGINX to the rescue!!!
If you were to let me specify a port, say 1234, but the server runs on a different port, say 4567, I can have my nginx redirect port 1234 (in ssl) to talk to non-ssl port 4567. And thus I can have ssl in my development environment and still get live reloading.
Ok, this is a bit of a weird one. Pow can be configured to proxy to a port. For example, I could run thin on port 3000.
If I echo 3000 > ~/.pow/foo
then go to http://foo.dev
I would see what is running on thin.
The very first request is fine. Every subsequent request fails to load assets. This is only the case if rack-livereload is running. If I go to http://foo.dev:3000
or http://localhost:3000
all is fine.
Hi,
Livereload works fine except when an error page from better_errors gem is shown. When that happens, I need to manually hit Command+R to reload a page. I've already posted this on guard-livereload gem page, but then realized that reloading is handled via rack-livereload. Not sure where exactly to report this issue.
Thanks.
I am trying to get livereload to work, but nothing seems to work.
# livereload
config.middleware.insert_before(
Rack::Lock, Rack::LiveReload,
:min_delay => 500,
:max_delay => 10000,
:port => 80,
:host => 'myapp.dev'
)
Am I missing something here?
To works with turbolinks livereload need to be loaded before application.js (and turbolinks.js), could you modify livereload injection to handle that issue? Thanks a lot!
While I get that this isn't a huge deal in development, I'd prefer if the CSP rules in development mode mostly matched the ones I'd like to use in production so that developers know if they are violating CSP rules.
This script is the main problem, assuming SWF is off.
<script type="text/javascript">
RACK_LIVERELOAD_PORT = 35729;
</script>
I'm trying to think of ways this could be done without an inline script. Possibly a data attribute?
The BodyProcessor does a naive regex search for all text looking like <head>
and injects it's script tags and code in that location. There are various valid situations where the text <head>
can exist in an HTML page without them actually being an element in the DOM (but instead just simply text).
Here are some examples of where the text <head>
could validly exist but would be wrong to inject the live reload code into:
<script type="text/template"></script>
section<head>
inside a comment<xmp>
tagsThere may be more but these are the ones I can think of. The first 1 is the worst because it is within a <script>
element and the injected code contains <script>
tags as well the rule for script tags is the first closing </script>
tag discovered always closes any open <script>
element (you cannot nest script elements). So this ends up leaving fragments of code afterwards because the browser makes it just past the first script tag in the injected code and then starts printing the rest as text or code fragments and it leaves the template code all over the page as well because the browser doesn't realize it's still inside a <script type="text/template">
section.
Maybe looking into a solution using built in XML parsing in Ruby that will find only <head>
tags that are part of the DOM and not just all text that happens to look like a <head>
tag would work?
I can research this but I wanted to post the issue first to see if there were any comments.
Hi!
Is possible the rack-livereload continue refreshing the browser after a Rails exception?
I hate need to refresh the browser manually after my code fails.
thanks!
I added rack live reload on development:
group :development do
gem 'guard-rspec'
gem 'guard-livereload'
gem 'rack-livereload'
gem 'rb-inotify', :require => false
gem 'rb-fsevent', :require => false
gem 'rb-fchange', :require => false
end
Added this line to development.rb:
config.middleware.insert_after(ActionDispatch::Static, Rack::LiveReload)
Bundle install, restart 'rails s'. I don't see anything about livereload.js in the http://localhost:3000/ source. What am I missing?
When the current page was loaded from a POST request, there's no good way for LiveReload to reload the page. This often comes up when I hit a POST action with an error. If something triggers LiveReload, it refreshes the page and my error message and backtrace disappear.
It would be nice if it were disabled on pages which came from POST requests. It would be nicer if only HTML reloading were disabled, but asset reloading were not.
0.3.5 is throwing these errors all over the place. Not happening with 0.3.4
Hi,
Is it possible to trigger a live reload via the terminal?
Hi,
The guard output sais the browser has connected and it discovers when files has changed.
But the browser will not reload.
Any idea what might be wrong? I could not see any new JavaScript being injected in the HTML header, when I inspected that. Should it?
$ guard
Guard could not detect any of the supported notification libraries.
Guard is now watching at '/Users/martins/Work/martinstabenfeldt.no'
LiveReload 1.6 is waiting for a browser to connect.
Then I refresh brower at http://0.0.0.0:3000/
Reloading browser: public/javascripts/translations.js
If i change one of the files...
Reloading browser: app/stylesheets/pages/_about.sass
But still, no refreshing is done of the page. Tried with both Safari and Chrome. :(
Gemfile:
group :development do
gem 'guard'
gem 'growl'
gem 'guard-livereload'
end
Guardfile
guard 'livereload', :apply_css_live => true, :apply_js_live => true, :host => '127.0.0.1' do
watch(%r{app/views/.+\.(erb|haml|slim)})
watch(%r{app/helpers/.+\.rb})
watch(%r{public/.+\.(js|html)})
watch(%r{config/locales/.+\.yml})
# Rails Assets Pipeline
watch(%r{(app|vendor)/assets/\w+/(.+\.(css|js|html)).*}) { |m| "/assets/#{m[2]}" }
watch(%r{app/stylesheets/layout/.+\.sass})
watch(%r{app/stylesheets/pages/_about.sass})
end
Cheers,
Martin
I haven't figured out yet why this happens. But while using rack-livereload on Windows the requests take around 1.5 seconds more than normal. I assume the requests are going to take a little bit longer with an additional middleware, but 1.5 seconds seems like an excess with a problem somewhere.
I don't remember having this issue on Linux though.
It happened on Rails 4 and also while using Middleman.
I'm willing to take a look when I have time, specially since there aren't many devs working on Windows :P. But yeah, better leave the report here first :).
I'm a newbie to Sinatra and this plugin, and I'm having a lot of trouble getting this to work for a very simple app.
I've created a new repo demonstrating how I'm using it and how it's failing, here: https://github.com/smoll/sinatra-livereload-example
In fact, I don't see the <script>
tag being injected into the markup at all:
Any ideas what I'm doing wrong?
Drupal themer coming from a sass/compass background. I am familiar with config.rb files and that's about it, when it comes to ruby.
I have my guard and guard-livereload working just fine, but trying to move onto getting rack-livereload functionality as I definitely use it on other devices by accessing my local server via port numbers for testing sites on other devices (A combination of my drupal theme and virtualhost setup accomplishes this)
The readme mentions using in Rails and using in Sinatra. These are both foreign to me so I am not sure how I implement this into a standard website project, not even Drupal related.
Do I need to recreate an environment such as config/environments/development.rb?
Do I need to modify my Gemfile to include rack-livereload?
I have disabled my chrome extension browser and have turned off my LiveReload application, just relying on the Guard LiveReload for now.
When I run "Guard", it just says "LiveReload waiting for browser connect."
I am not sure if I ma missing anything from the instructions (such as a command, file name or perhaps I just don't understand). Please let me know if I am missing something obvious or if more information about my setup is required.
Thanks in advance.
edit: Also forgot to mention, the config.rb file I have is used with the Drupal theme, so I will still be needing it. I am not sure if this creates conflict somehow.
When using config.threadsafe!
there is no Rack::Lock middleware, so
config.middleware.insert_before(Rack::Lock, Rack::LiveReload)
will not work.
I'd suggest using
config.middleware.insert_after(ActionDispatch::Static, Rack::LiveReload)
instead - works for both cases.
I'm kind of new to the whole ruby ecosystem and hope my question isn't too far-fetched.
What i'm currently trying to do is to build a basic dev setup for new projects starting thin webserver and guard via foreman.
Once i specify a non-standard port instead of 9292 in the first line of my config.ru to get my pages served from http://localhost:1337/ or others, livereload stops working because browsers are not able to connect via websocket to ws://localhost:35729/livereload (readyState 3).
config.ru
#\ -p 1337
require "rack-server-pages"
require "rack-livereload"
use Rack::LiveReload
run Rack::ServerPages
Procfile
guard: bundle exec guard
web: bundle exec rackup
Guardfile
guard 'sass', :input => 'sass', :output => 'public/css'
guard 'coffeescript', :input => 'coffee', :output => 'public/js'
guard 'livereload' do
watch(%r{public/.+\.(css|js|html)})
end
Could this be a bug?
I've tried with "rails s" --> running WEBrick and also with my default app local domain..
hartl.dev
but I'm always getting an issue with guard detecting the changes and generating seemingly correct output like this...
01:46:23 - INFO - Reloading browser: app/views/info_pages/faq.html.erb
01:49:09 - INFO - Pow restarted.
01:49:31 - INFO - Reloading browser: app/views/info_pages/faq.html.erb
01:50:00 - INFO - Reloading browser: app/views/info_pages/faq.html.erb
but the browsers are not reloading at all.. I tried chrome and safari. When I inspect the network tab in chrome.. i see a lot of blank-icon (no extension) "livereload" files queueing up...
Is there any fix for such an issue? This happens on mac 10.8.2 btw.
Guard shows that when I edit a page, eg. application.html.slim that the change has been detected. The browser however does not reload. I am using Linux Mint and Chrome.
In my development.rb file I have the following:
config.middleware.insert_after(ActionDispatch::Static, Rack::LiveReload)
My guard file:
guard 'livereload' do
watch(%r{app/views/.+\.(erb|haml|slim)$})
watch(%r{app/views/.+\.(erb|haml|slim)$})
watch(%r{app/presenters/.+\.rb})
watch(%r{public/.+\.(css|js|html)})
watch(%r{config/locales/.+\.yml})
# Rails Assets Pipeline
watch(%r{(app|vendor)(/assets/\w+/(.+\.(css|js|html))).*}) { |m| "/assets/#{m[3]}" }
end
lee@lee-mint ~/code/cassandra $ guard
11:57:20 - INFO - Guard uses NotifySend to send notifications.
11:57:20 - INFO - Guard uses TerminalTitle to send notifications.
11:57:20 - INFO - Running annotate
Nothing annotated.
Route file annotated.
11:57:30 - INFO - LiveReload is waiting for a browser to connect.
11:57:30 - INFO - [Guard::Rails] will restart on port 3000 in development.
11:57:30 - INFO - Starting Rails...
=> Booting WEBrick
=> Rails 4.0.0 application starting in development on http://0.0.0.0:3000
=> Run `rails server -h` for more startup options
=> Ctrl-C to shutdown server
[2013-07-09 11:58:03] INFO WEBrick 1.3.1
[2013-07-09 11:58:03] INFO ruby 2.0.0 (2013-05-14) [x86_64-linux]
[2013-07-09 11:58:03] INFO WEBrick::HTTPServer#start: pid=6363 port=3000
Started GET "/" for 127.0.0.1 at 2013-07-09 11:58:05 +0200
ActiveRecord::SchemaMigration Load (0.3ms) SELECT "schema_migrations".* FROM "schema_migrations"
Processing by PagesController#root as HTML
Rendered pages/root.html.slim within layouts/application (11.5ms)
Completed 200 OK in 252ms (Views: 243.4ms | ActiveRecord: 0.0ms)
11:58:06 - INFO - Rails started, pid 6363
11:58:06 - INFO - Guard is now watching at '/home/lee/code/cassandra'
[1] guard(main)>
Started GET "/" for 127.0.0.1 at 2013-07-09 11:58:23 +0200
Processing by PagesController#root as HTML
Rendered pages/root.html.slim within layouts/application (0.2ms)
Completed 200 OK in 13ms (Views: 12.3ms | ActiveRecord: 0.0ms)
Started GET "/__meta_request/83beb7a9-0efc-4c2e-8435-4a72030a8661.json" for 127.0.0.1 at 2013-07-09 11:58:23 +0200
11:58:54 - INFO - Reloading browser: app/views/layouts/application.html.slim app/views/layouts/application.html.slim
[1] guard(main)>
I'm getting this javascript error in Chrome with the latest version of rack-livereload.
I just upgraded to Rails 5, and I get this error:
=> Booting WEBrick
=> Rails 5.0.1 application starting in development on http://0.0.0.0:3001
=> Run `rails server -h` for more startup options
Exiting
/Users/josh/.rvm/gems/ruby-2.2.5@base/gems/actionpack-5.0.1/lib/action_dispatch/middleware/stack.rb:108:in `assert_index': No such middleware to insert before: Rack::Lock (RuntimeError)
from /Users/josh/.rvm/gems/ruby-2.2.5@base/gems/actionpack-5.0.1/lib/action_dispatch/middleware/stack.rb:73:in `insert'
It's because I use better_errors gem. I have changed my config from
config.middleware.insert_before Rack::Lock, Rack::LiveReload, no_swf: true,
live_reload_port: 35729
to
config.middleware.insert_before ActionDispatch::DebugExceptions, Rack::LiveReload, no_swf: true,
live_reload_port: 35729
which seems to work.
In rack-livereload's README you still state to use Rack::Lock
, maybe you should update it:
It's not clear from the README.md
when you should do
config.middleware.insert_after(ActionDispatch::Static, Rack::LiveReload)
vs.
config.middleware.insert_before(
Rack::Lock, Rack::LiveReload,
...
In fact, it makes it look like you would only do the latter when you want to set options, but this appears to be incorrect and misleading.
Hi!
This error occurs when getting the image that is generated for the captcha.
Here log:
/home/csolg/.rvm/gems/ruby-1.9.3-p392/gems/actionpack-3.2.12/lib/action_dispatch/middleware/body_proxy.rb:27:in `each'
/home/csolg/.rvm/gems/ruby-1.9.3-p392/gems/actionpack-3.2.12/lib/action_dispatch/middleware/body_proxy.rb:27:in `method_missing'
/home/csolg/.rvm/gems/ruby-1.9.3-p392/gems/rack-1.4.5/lib/rack/body_proxy.rb:31:in `each'
/home/csolg/.rvm/gems/ruby-1.9.3-p392/bundler/gems/rack-livereload-c1415c32cb42/lib/rack/livereload.rb:66:in `_call'
/home/csolg/.rvm/gems/ruby-1.9.3-p392/bundler/gems/rack-livereload-c1415c32cb42/lib/rack/livereload.rb:51:in `call'
/home/csolg/.rvm/gems/ruby-1.9.3-p392/gems/actionpack-3.2.12/lib/action_dispatch/middleware/static.rb:62:in `call'
/home/csolg/.rvm/gems/ruby-1.9.3-p392/gems/railties-3.2.12/lib/rails/engine.rb:479:in `call'
/home/csolg/.rvm/gems/ruby-1.9.3-p392/gems/railties-3.2.12/lib/rails/application.rb:223:in `call'
/home/csolg/.rvm/gems/ruby-1.9.3-p392/gems/rack-1.4.5/lib/rack/content_length.rb:14:in `call'
/home/csolg/.rvm/gems/ruby-1.9.3-p392/gems/railties-3.2.12/lib/rails/rack/log_tailer.rb:17:in `call'
/home/csolg/.rvm/gems/ruby-1.9.3-p392/gems/rack-1.4.5/lib/rack/handler/webrick.rb:59:in `service'
/home/csolg/.rvm/rubies/ruby-1.9.3-p392/lib/ruby/1.9.1/webrick/httpserver.rb:138:in `service'
/home/csolg/.rvm/rubies/ruby-1.9.3-p392/lib/ruby/1.9.1/webrick/httpserver.rb:94:in `run'
/home/csolg/.rvm/rubies/ruby-1.9.3-p392/lib/ruby/1.9.1/webrick/server.rb:191:in `block in start_thread'
Could not find the license.
when I using http streaming:
def show
render stream: true
end
content of the webpage is truncated. after remove the middleware of livereload, it works fine.
livereload.js Line: 725
Hi, I use rack-reload with guard-livereload and it works great. However, I also often run under a regular web server, as guard tends to interfere with setting binding.pry
and debugging.
Would it be possible to add a configuration option to rack-livereload so that it only serves Javascript when being served from guard, but not when being served from unicorn (and other non-livereload-capable servers?)
Of course, it's not a big deal for livereload to be loaded and unused, but I just wanted to avoid the console errors "WebSocket connection to 'ws://localhost:35729/livereload' failed: Error in connection establishment: net::ERR_CONNECTION_REFUSED". Thanks.
Thanks.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.