Skip to content

Commit

Permalink
update loaded middlewares and use of Rack::Server instead of Rack::Bu…
Browse files Browse the repository at this point in the history
…ilder
  • Loading branch information
rafmagana committed May 23, 2012
1 parent 83f62a0 commit 56ad6ca
Showing 1 changed file with 33 additions and 13 deletions.
46 changes: 33 additions & 13 deletions guides/source/rails_on_rack.textile
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -27,25 +27,45 @@ h4. Rails Application's Rack Object


h4. +rails server+ h4. +rails server+


<tt>rails server</tt> does the basic job of creating a +Rack::Builder+ object and starting the webserver. This is Rails' equivalent of Rack's +rackup+ script. <tt>rails server</tt> does the basic job of creating a +Rack::Server+ object and starting the webserver.


Here's how +rails server+ creates an instance of +Rack::Builder+ Here's how +rails server+ creates an instance of +Rack::Server+


<ruby> <ruby>
app = Rack::Builder.new { Rails::Server.new.tap { |server|
use Rails::Rack::LogTailer unless options[:detach] require APP_PATH
use Rails::Rack::Debugger if options[:debugger] Dir.chdir(Rails.application.root)
use ActionDispatch::Static server.start
run ApplicationName::Application }
}.to_app
</ruby> </ruby>


Middlewares used in the code above are primarily useful only in the development environment. The following table explains their usage: The +Rails::Server+ inherits from +Rack::Server+ and calls the +Rack::Server#start+ method this way:

<ruby>
class Server < ::Rack::Server
def start
...
super
end
end
</ruby>

Here's how it loads the middlewares:

<ruby>
def middleware
middlewares = []
middlewares << [Rails::Rack::Debugger] if options[:debugger]
middlewares << [::Rack::ContentLength]
Hash.new(middlewares)
end
</ruby>

+Rails::Rack::Debugger+ is primarily useful only in the development environment. The following table explains the usage of the loaded middlewares:


|_.Middleware|_.Purpose| |_.Middleware|_.Purpose|
|+Rails::Rack::LogTailer+|Appends log file output to console|
|+ActionDispatch::Static+|Serves static files inside +Rails.root/public+ directory|
|+Rails::Rack::Debugger+|Starts Debugger| |+Rails::Rack::Debugger+|Starts Debugger|
|+Rack::ContentLength+|Counts the number of bytes in the response and set the HTTP Content-Length header|


h4. +rackup+ h4. +rackup+


Expand All @@ -55,8 +75,8 @@ To use +rackup+ instead of Rails' +rails server+, you can put the following insi
# Rails.root/config.ru # Rails.root/config.ru
require "config/environment" require "config/environment"


use Rails::Rack::LogTailer use Rack::Debugger
use ActionDispatch::Static use Rack::ContentLength
run ApplicationName::Application run ApplicationName::Application
</ruby> </ruby>


Expand Down

0 comments on commit 56ad6ca

Please sign in to comment.