add the ability to ignore certain urls that may match
This commit is contained in:
parent
aaa701bac9
commit
20ef5cc1f3
|
@ -25,7 +25,8 @@ MyApp::Application.configure do
|
||||||
:min_delay => 500,
|
:min_delay => 500,
|
||||||
:max_delay => 10000,
|
:max_delay => 10000,
|
||||||
:port => 56789,
|
:port => 56789,
|
||||||
:host => 'myhost.cool.wow'
|
:host => 'myhost.cool.wow',
|
||||||
|
:ignore => [ %r{dont/modify\.html$} ]
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
```
|
```
|
||||||
|
|
|
@ -48,35 +48,37 @@ module Rack
|
||||||
else
|
else
|
||||||
status, headers, body = @app.call(env)
|
status, headers, body = @app.call(env)
|
||||||
|
|
||||||
case headers['Content-Type']
|
if !@options[:ignore] || !@options[:ignore].any? { |filter| path[filter] }
|
||||||
when %r{text/html}
|
case headers['Content-Type']
|
||||||
content_length = 0
|
when %r{text/html}
|
||||||
|
content_length = 0
|
||||||
|
|
||||||
body.each do |line|
|
body.each do |line|
|
||||||
if !headers['X-Rack-LiveReload'] && line['</head>']
|
if !headers['X-Rack-LiveReload'] && line['</head>']
|
||||||
host_to_use = (@options[:host] || env['HTTP_HOST'] || 'localhost').gsub(%r{:.*}, '')
|
host_to_use = (@options[:host] || env['HTTP_HOST'] || 'localhost').gsub(%r{:.*}, '')
|
||||||
|
|
||||||
if use_vendored?
|
if use_vendored?
|
||||||
src = LIVERELOAD_JS_PATH.dup + "?host=#{host_to_use}"
|
src = LIVERELOAD_JS_PATH.dup + "?host=#{host_to_use}"
|
||||||
else
|
else
|
||||||
src = LIVERELOAD_LOCAL_URI.dup.gsub('localhost', host_to_use) + '?'
|
src = LIVERELOAD_LOCAL_URI.dup.gsub('localhost', host_to_use) + '?'
|
||||||
|
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]
|
||||||
|
|
||||||
|
template = ERB.new(::File.read(::File.expand_path('../../../skel/livereload.html.erb', __FILE__)))
|
||||||
|
|
||||||
|
line.gsub!('</head>', %{#{template.result(binding)}</head>})
|
||||||
|
|
||||||
|
headers["X-Rack-LiveReload"] = '1'
|
||||||
end
|
end
|
||||||
|
|
||||||
src << "&mindelay=#{@options[:min_delay]}" if @options[:min_delay]
|
content_length += line.length
|
||||||
src << "&maxdelay=#{@options[:max_delay]}" if @options[:max_delay]
|
|
||||||
src << "&port=#{@options[:port]}" if @options[:port]
|
|
||||||
|
|
||||||
template = ERB.new(::File.read(::File.expand_path('../../../skel/livereload.html.erb', __FILE__)))
|
|
||||||
|
|
||||||
line.gsub!('</head>', %{#{template.result(binding)}</head>})
|
|
||||||
|
|
||||||
headers["X-Rack-LiveReload"] = '1'
|
|
||||||
end
|
end
|
||||||
|
|
||||||
content_length += line.length
|
headers['Content-Length'] = content_length.to_s
|
||||||
end
|
end
|
||||||
|
|
||||||
headers['Content-Length'] = content_length.to_s
|
|
||||||
end
|
end
|
||||||
|
|
||||||
[ status, headers, body ]
|
[ status, headers, body ]
|
||||||
|
|
|
@ -132,6 +132,15 @@ describe Rack::LiveReload do
|
||||||
body.should include('localhost')
|
body.should include('localhost')
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context 'ignored' do
|
||||||
|
let(:options) { { :ignore => [ %r{file} ] } }
|
||||||
|
let(:env) { { 'PATH_INFO' => 'this/file' } }
|
||||||
|
|
||||||
|
it 'should have no change' do
|
||||||
|
body.should_not include('script')
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context '/__rack/livereload.js' do
|
context '/__rack/livereload.js' do
|
||||||
|
|
Loading…
Reference in New Issue