1
0
Fork 0
mirror of https://github.com/sinatra/sinatra synced 2023-03-27 23:18:01 -04:00

fix root path detection under thin/passenger

Fixed how the Sinatra application's path is set. Previously it
was derived exclusively from $0, but this was causing problems
when running Sinatra under Rack because $0 is the web server
(e.g., thin, passenger, etc) and thus Sinatra would incorrectly
set things like the default views path. This fix adds a new
locate_app_file method that uses a number of techniques to guess the
Sinatra application's path.
This commit is contained in:
Igal Koshevoy 2008-11-04 03:35:09 -08:00 committed by Ryan Tomayko
parent b03d7171d9
commit 68d76aa504
2 changed files with 16 additions and 2 deletions

View file

@ -2,6 +2,9 @@
* BUG: use_in_file_templates! failes with CR/LF (#45)
* BUG: Sinatra detects the app file and root path when run under
thin/passenger.
= 0.3.2
* BUG: Static and send_file read entire file into String before

View file

@ -923,7 +923,8 @@ module Sinatra
# file, before any DSL related functions are invoked.
def self.default_options
return @default_options unless @default_options.nil?
root = File.expand_path(File.dirname($0))
app_file = locate_app_file
root = File.expand_path(File.dirname(app_file))
@default_options = {
:run => true,
:port => 4567,
@ -934,7 +935,7 @@ module Sinatra
:public => root + '/public',
:sessions => false,
:logging => true,
:app_file => $0,
:app_file => app_file,
:raise_errors => false
}
load_default_options_from_command_line!
@ -957,6 +958,16 @@ module Sinatra
end.parse!(ARGV.dup.select { |o| o !~ /--name/ })
end
# Use heuristics to locate the application file.
def self.locate_app_file
caller[1..-1].reverse.each do |path|
path = path.split(':', 2)[0]
next if path =~ /sinatra\.rb$/ || path == '(__DSL__)'
return path
end
$0
end
# Determine whether the application is in the process of being
# reloaded.
def reloading?