Handle Rails apps running on relative root #27

Merged
adamlogic merged 1 commits from master into master 2013-04-02 15:22:50 +00:00
3 changed files with 14 additions and 3 deletions

View File

@ -77,8 +77,10 @@ module Rack
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{:.*}, '')
app_root = ENV['RAILS_RELATIVE_URL_ROOT'] || ''
if use_vendored? if use_vendored?
src = LIVERELOAD_JS_PATH.dup + "?host=#{host_to_use}" src = "#{app_root}#{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 end

View File

@ -5,8 +5,8 @@
WEB_SOCKET_FORCE_FLASH = true; WEB_SOCKET_FORCE_FLASH = true;
<% end %> <% end %>
</script> </script>
<script type="text/javascript" src="/__rack/swfobject.js"></script> <script type="text/javascript" src="<%= app_root %>/__rack/swfobject.js"></script>
<script type="text/javascript" src="/__rack/web_socket.js"></script> <script type="text/javascript" src="<%= app_root %>/__rack/web_socket.js"></script>
<% end %> <% end %>
<script type="text/javascript"> <script type="text/javascript">
RACK_LIVERELOAD_PORT = <%= @port %>; RACK_LIVERELOAD_PORT = <%= @port %>;

View File

@ -161,6 +161,15 @@ describe Rack::LiveReload do
body_dom.at_css("script:last-child")[:insert].should == "before" body_dom.at_css("script:last-child")[:insert].should == "before"
end end
context 'when a relative URL root is specified' do
before do
ENV['RAILS_RELATIVE_URL_ROOT'] = '/a_relative_path'
end
it 'should prepend the relative path to the script src' do
body_dom.at_css("script:eq(5)")[:src].should match(%r{^/a_relative_path/})
end
end
end end
describe "LIVERELOAD_PORT value" do describe "LIVERELOAD_PORT value" do