Created
October 13, 2013 15:09
-
-
Save indyarocks/6963372 to your computer and use it in GitHub Desktop.
Exploring Rack.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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