Rackables¶ ↑
A collection of useful Rack middleware, and more
Middleware¶ ↑
-
Rackables::Branch - Conditionally re-routes the Rack stack at runtime to an alternate endpoint
-
Rackables::CacheControl - Sets response Cache-Control header
-
Rackables::DefaultCharset - Sets charset directive in Content-Type header
-
Rackables::SimpleEndpoint - Allows creation of simple endpoints and path routing with a syntax similar to Sinatra’s get method
-
Rackables::HideExceptions - Rescues exceptions with a static exception page
-
Rackables::ResponseHeaders - Allows adding and removing of response headers at runtime
-
Rackables::TrailingSlashRedirect - 301 Redirects requests paths with a trailing slash
More¶ ↑
Rackables also bundles a Rack environment inquirer similar to Rails.env:
Rack.env # => "development" Rack.env.development? # => true
Use¶ ↑
Rackables is hosted as a gem on Gemcutter, so you just need to:
sudo gem install rackables
or if you wish to bundle with an app that uses Bundler, you just need to add this to your Gemfile:
gem "rackables"
Requiring ‘rackables’ will add autoloads for all Rackables middlewares. To use the Rack.env inquirer, you must explicitly require “rackables/more/env_inquirer”.
Example config.ru:
require 'rackables' require 'rackables/more/env_inquirer' require 'my_endpont_app' if Rack.env.development? use Rack::ShowExceptions else use Rackables::HideExceptions, 'public/500.html' end use Rackables::TrailingSlashRedirect use Rackables::CacheControl, :public, :max_age => 60 use Rackables::DefaultCharset, 'utf-8' use Rackables::ResponseHeaders do |headers| headers['X-Foo'] = 'foo' end use Rackables::SimpleEndpoint, '/ping_monitor' do "pong" end use Rackables::Branch do |env| Rack::Lobster if env["PATH_INFO"] =~ /^\/lobster$/ end run MyEndpointApp