Sinatra is Rack compatible and thus deploying behind Phusion Passenger works well. Unfortunately, the documentation on the Passenger site leaves a bit to be desired and may leave you scratching your head as to why your Sinatra application isn't working correctly. Here is a sample config.ru script that will bring up your application behind passenger with an explanation coming after the code:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
root_dir = File.dirname(__FILE__) | |
if !defined?(Sinatra) | |
$:.unshift "#{root_dir}/vendor/sinatra/lib" if File.directory?("#{root_dir}/vendor/sinatra") | |
end | |
require 'rubygems' | |
require 'sinatra' | |
Sinatra::Application.default_options.merge!( | |
:views => File.join(root_dir, 'views'), | |
:app_file => File.join(root_dir, 'app.rb'), | |
:run => false, | |
:env => ENV['RACK_ENV'].to_sym | |
) | |
require 'app' |
First off, my config.ru provides the ability to "freeze" to a certain version of Sinatra with the $:.unshift line near the top of the file. This line just checks for the existence of a vendor/sinatra directory in your application and if present pushes its lib directory to the front of the load path. The setup of the default options is where I add some information not given by the Passenger instructions which will otherwise cause your application to fall down go boom - that is you must tell Sinatra how to find its views directory (so that you can use views) and its app_file (so that it will reload correctly when running under :development mode). Also notice how the environment is picked up from the RackEnv variable coming from the conf file. The real guts of the application are defined in app.rb which is required at the bottom of the file.
This is my first post using gist to host code snippets and it seems to be a winner. I think I will also start hosting my Javascript example code straight out of gist raw as well.