From eccebca01f9f2065da7c2149c2d04e88a93e45ff Mon Sep 17 00:00:00 2001 From: John Bintz Date: Mon, 7 Nov 2011 09:11:27 -0500 Subject: [PATCH] override the host. now it is complete. no more changes ever need to be made to this. ever. --- README.md | 7 ++----- lib/rack/livereload.rb | 6 +++++- spec/rack/livereload_spec.rb | 4 +++- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 0796f41..0211b62 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,8 @@ MyApp::Application.configure do Rack::Lock, Rack::LiveReload, :min_delay => 500, :max_delay => 10000, - :port => 56789 + :port => 56789, + :host => 'myhost.cool.wow' ) end ``` @@ -42,9 +43,5 @@ such a way that the `HTTP_HOST` is used as the LiveReload host, so you can conne `mycomputer:3000` instead of `localhost:3000`) and as long as the LiveReload port is accessible from the external machine, you'll connect and be LiveReloading away! -## To-do - -* Override the `host` - As usual, super-alpha! diff --git a/lib/rack/livereload.rb b/lib/rack/livereload.rb index 96d1d7a..09b399e 100644 --- a/lib/rack/livereload.rb +++ b/lib/rack/livereload.rb @@ -22,7 +22,11 @@ def call(env) body.each do |line| if !headers['X-Rack-LiveReload'] && line[''] src = LIVERELOAD_JS_PATH.dup - src << "?host=#{env['HTTP_HOST'].gsub(%r{:.*}, '')}" if env['HTTP_HOST'] + if @options[:host] + src << "?host=#{@options[:host]}" + else + src << "?host=#{env['HTTP_HOST'].gsub(%r{:.*}, '')}" if env['HTTP_HOST'] + end src << "&mindelay=#{@options[:min_delay]}" if @options[:min_delay] src << "&maxdelay=#{@options[:max_delay]}" if @options[:max_delay] src << "&port=#{@options[:port]}" if @options[:port] diff --git a/spec/rack/livereload_spec.rb b/spec/rack/livereload_spec.rb index a6d7207..3b1e9de 100644 --- a/spec/rack/livereload_spec.rb +++ b/spec/rack/livereload_spec.rb @@ -44,15 +44,17 @@ end context 'set options' do - let(:middleware) { described_class.new(app, :port => port, :min_delay => min_delay, :max_delay => max_delay) } + let(:middleware) { described_class.new(app, :host => new_host, :port => port, :min_delay => min_delay, :max_delay => max_delay) } let(:min_delay) { 5 } let(:max_delay) { 10 } let(:port) { 23 } + let(:new_host) { 'myhost' } it 'should add the livereload.js script tag' do body.should include("mindelay=#{min_delay}") body.should include("maxdelay=#{max_delay}") body.should include("port=#{port}") + body.should include("host=#{new_host}") end end end