Skip to content

Commit

Permalink
override the host. now it is complete. no more changes ever need to b…
Browse files Browse the repository at this point in the history
…e made to this. ever.
  • Loading branch information
johnbintz committed Nov 7, 2011
1 parent ccf888d commit eccebca
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
7 changes: 2 additions & 5 deletions README.md
Expand Up @@ -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
```
Expand All @@ -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!

6 changes: 5 additions & 1 deletion lib/rack/livereload.rb
Expand Up @@ -22,7 +22,11 @@ def call(env)
body.each do |line|
if !headers['X-Rack-LiveReload'] && line['</head>']
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]
Expand Down
4 changes: 3 additions & 1 deletion spec/rack/livereload_spec.rb
Expand Up @@ -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
Expand Down

0 comments on commit eccebca

Please sign in to comment.