From 3adce6a1a803a00cb5cc9da758a10a658aab98ec Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Tue, 31 Mar 2009 17:10:49 -0700 Subject: [PATCH] unicorn_rails: cleanup path mapping usage Just use the RAILS_RELATIVE_URL_ROOT variable to support it since probably works on more versions of Rails. Since no application I've ever deployed has ever used it, I'm not going to bother supporting it for Rails <2.3, either. --- bin/unicorn_rails | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/bin/unicorn_rails b/bin/unicorn_rails index 4299fb5a..fa0a9b72 100755 --- a/bin/unicorn_rails +++ b/bin/unicorn_rails @@ -81,7 +81,7 @@ opts = OptionParser.new("", 24, ' ') do |opts| opts.on("-P", "--path PATH", "Runs Rails app mounted at a specific path.", "(default: /") do |v| - map_path = v + ENV['RAILS_RELATIVE_URL_ROOT'] = map_path = v end # I'm avoiding Unicorn-specific config options on the command-line. @@ -126,8 +126,12 @@ rails_loader = lambda do || defined?(::Rails::VERSION::STRING) or abort "Rails::VERSION::STRING not defined by config/boot" rescue LoadError => err - abort "#$0 must be run inside RAILS_ROOT=(#{::RAILS_ROOT}) #{err.inspect}" + abort "#$0 must be run inside RAILS_ROOT: #{err.inspect}" end + defined?(::RAILS_ROOT) or abort "RAILS_ROOT not defined by config/boot" + defined?(::RAILS_ENV) or abort "RAILS_ENV not defined by config/boot" + defined?(::Rails::VERSION::STRING) or + abort "Rails::VERSION::STRING not defined by config/boot" case config when nil @@ -166,11 +170,15 @@ app = lambda do || inner_app = rails_loader.call require 'active_support' require 'action_controller' - ActionController::Base.relative_url_root = map_path if map_path map_path ||= '/' inner_app = inner_app.call Rack::Builder.new do if inner_app.class.to_s == "Unicorn::App::OldRails" + if map_path != '/' + # patches + tests welcome, but I really cbf to deal with this + # since all apps I've ever dealt with just use "/" ... + $stderr.puts "relative URL roots may not work for older Rails" + end $stderr.puts "LogTailer not available for Rails < 2.3" unless daemonize $stderr.puts "Debugger not available" if $DEBUG map(map_path) do -- 2.11.4.GIT