Skip to content

Latest commit

 

History

History
23 lines (17 loc) · 1.18 KB

middleware.textile

File metadata and controls

23 lines (17 loc) · 1.18 KB

:title: The TinySite middleware
:description: TinySite middleware usage

++++body++++

Using Rack middleware with TinySite

If you don’t know, what “Rack middleware” even means head over to the Railscasts right now! Basically middlewares allow you to modify requests on their way to and responses on their way from any Rack based webapp. You definitely should use Rack::ContentLength1 with TinySite or it’s responses won’t even be valid HTTP. Rack::Static1 is highly recommended for handling your assets like css and javascript files. I combined it with Rack::Rewrite to provide a favicon.ico and a robots.txt on root level. Rack::CommonLogger1 is useful to have any log output.

The complete middleware configuration of this very app looks somewhat like this:

use Rack::Runtime
use Rack::CommonLogger
use Rack::ContentLength
use Rack::Rewrite do
  rewrite '/robots.txt', '/static/robots.txt'
  rewrite '/favicon.ico', '/static/favicon.ico'
end
use Rack::Static, :urls => ['/stylesheets','/javascript','/static'], :root => 'public'

1 Part of Rack