the end of tying applications to a dispatcher / handler • Before then we had application dispatchers, CGI, FCGI • Communication between Rails and any web server is simpli ed Rails < 2.3 Wednesday, 28 March 12
and CGI starts a new process for every request... • Your application needs to know about wether it runs under CGI, FCGI etc. • Applications are more portable Wednesday, 28 March 12
Rack::Runtime use Rack::MethodOverride use ActionDispatch::RequestId use Rails::Rack::Logger use ActionDispatch::ShowExceptions use ActionDispatch::DebugExceptions use ActionDispatch::RemoteIp use ActionDispatch::Reloader use ActionDispatch::Callbacks use ActiveRecord::ConnectionAdapters::ConnectionManagement use ActiveRecord::QueryCache use ActionDispatch::Cookies use ActionDispatch::Session::CookieStore use ActionDispatch::Flash use ActionDispatch::ParamsParser use ActionDispatch::Head use Rack::ConditionalGet use Rack::ETag use ActionDispatch::BestStandardsSupport run MyRailsApplication::Application.routes Wednesday, 28 March 12
Rack::Directory.new('.').call(env) end wee_rack_app = Rack::Builder.new do use Rack::ContentLength use Rack::ReverseProxy do reverse_proxy /^\/couchdb(.*)$/, 'http://127.0.0.1:5984$1' reverse_proxy /^\/api(.*)$/, 'http://127.0.0.1:4000$1' end run app end run wee_rack_app con g.ru Wednesday, 28 March 12
require "action_controller/railtie" #require "action_mailer/railtie" #require "active_resource/railtie" #require "rails/test_unit/railtie" if defined?(Bundler) # If you precompile assets before deploying to production, use this line # Bundler.require *Rails.groups(:assets => %w(development test)) # If you want your assets lazily compiled in production, use this line Bundler.require(:default, :assets, Rails.env) end module CouchbaseTinyurl class Application < Rails::Application # ... # Configure the default encoding used in templates for Ruby 1.9. config.encoding = "utf-8" # Configure sensitive parameters which will be filtered from the log file. config.filter_parameters += [:password] # Enable the asset pipeline config.assets.enabled = true end end application.rb Wednesday, 28 March 12
match "/hello/world" => "hello#world" end config.cache_classes = true # Enable cache classes. Production style. config.middleware.delete "Rack::Lock" config.middleware.delete "ActionDispatch::Flash" config.middleware.delete "ActionDispatch::BestStandardsSupport" config.secret_token = "49837489qkuweoiuoqwehisuakshdjksadhaisdy78o34y138974xyqp9rmye8yrpiokeuioqwzyoiuxftoyqiuxrhm3iou1hrzmjk" end class HelloController < ActionController::Metal include ActionController::Rendering def world render :text => "Hello world!" end end MyApp.initialize! run MyApp con g.ru Wednesday, 28 March 12