Skip to content

Instantly share code, notes, and snippets.

@indyarocks
Created October 13, 2013 15:09
Show Gist options
  • Save indyarocks/6963372 to your computer and use it in GitHub Desktop.
Save indyarocks/6963372 to your computer and use it in GitHub Desktop.
Exploring Rack.
# config.ru
require 'rack/lobster'
require 'logger'
infinity = Rack::Builder.new do
use Rack::CommonLogger
Logger.new('rack.log')
map '/' do
run Proc.new {|env| [200, {"Content-Type" => "text/html"}, ["hello"]]}
end
map '/secret' do
use Rack::Auth::Basic, "Restricted Area" do |user, password|
user == 'super' && password == 'secretsauce'
end
map '/' do
run Proc.new{|env| [200, {"Content-Type" => "text/html"}, ["Secret page"]]}
end
end
map '/version' do
map '/' do
run Proc.new{|env| [200, {"Content-Type" => "text/html"}, ["Infinity 0.1"]]}
end
map '/last' do
run Proc.new{|env| [200, {"Content-Type" => "text/html"}, ["Infinity Beta"]]}
end
end
end
class ToUpper
# Initialize another Rack app
def initialize(app)
@app = app
end
def call(env)
# First call @app
status, headers, body = @app.call(env)
# Upcase body
upcased_body = ""
body.each {|chunk| upcased_body << chunk.upcase }
# Pass new body
[status, headers, [upcased_body]]
end
end
use Rack::Reloader
use ToUpper
run infinity
#run Rack::Lobster.new
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment