views:

194

answers:

2

I have correctly (or prbably not) installed passenger on apache 2. Rack works, but sinatra keeps giving 404's.

Here is what works: config.ru:

#app = proc do |env|
  return [200, { "Content-Type" => "text/html" }, "hello <b>world</b>"]  
end
run app

Here is what works too: Running the app.rb (see below) with ruby app.rb and then looking at localhost:4567/about and /

restarting the app, gives me a correct hello world. w00t.

But then there is the sinatra entering the building: config.ru

require 'rubygems'
require 'sinatra'

root_dir = File.dirname(__FILE__)

set :environment, ENV['RACK_ENV'].to_sym
set :root,        root_dir
set :app_file,    File.join(root_dir, 'app.rb')
disable :run

run Sinatra::Application

and an app.rb

require 'rubygems'
require 'sinatra'

get '/' do 
 "Hallo wereld!"
end

get '/about' do
 "Hello world, it's #{Time.now} at the server!"
end

This keeps giving 404s. /var/logs/apache2/error.log lists these correctly as "404" with something that worries me:

83.XXXXXXXXX - - [30/May/2010 16:06:52] "GET /about " 404 18 0.0007
83.XXXXXXXXX - - [30/May/2010 16:06:56] "GET / " 404 18 0.0007

The thing that worried me, is the space after the / and the /about. Would apache or sinatra go looking for /[space], like /%20?

If anyone knows what this problem relates to, maybe a known bug (that I could not find) or a known gotcha? Maybe I am just being stupid and getting "it all wrong?"

Otherwise any hints on where to get, read or log more developers data on a running rack, sinatra or passenger app would be helpfull too: to see what sinatra is looking for, for example.

Some other information: Running ubuntu 9.04, apache2-mm-prefork (deb), mod_php5, ruby 1.8.7, passenger 2.2.11, sinatra 1.0

+2  A: 

You are not loading the routes in app.rb. To do this, replace require 'sinatra' with require File.join(File.dirname(__FILE__), 'app.rb') in config.ru.

root_dir = File.dirname(__FILE__)
app_file = File.join(root_dir, 'app.rb')
require app_file

set :environment, ENV['RACK_ENV'].to_sym
set :root,        root_dir
set :app_file,    app_file
disable :run

run Sinatra::Application

set :app_file won't load them for you.

Adrian
Thanks a million. I will try to get this fixed in the passenger documentation too. http://modrails.com/documentation/Users%20guide.html#_sinatra
berkes
A: 

Just substitute the require sinatra with a require 'app' and you're set to go.

asymmetric