Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Branch: master
Fetching contributors…

Cannot retrieve contributors at this time

53 lines (44 sloc) 1.113 kB
# Override Rack::Static to allow a fallthrough for missing files
module Rack
class Static
def initialize(app, options={})
@app = app
@urls = options[:urls] || ["/favicon.ico"]
@root = options[:root] || Dir.pwd
@file_server = Rack::File.new(@root)
end
def call(env)
path = env["PATH_INFO"]
can_serve = @urls.any? { |url| path.index(url) == 0 }
if can_serve && ::File.exist?("#{@root}/#{path}")
@file_server.call(env)
else
@app.call(env)
end
end
end
end
use Rack::Static, :urls => ["/"], :root => "lib"
use Rack::Static, :urls => ["/"], :root => "public"
current = Hash.new(0)
map "/favicon.ico" do
run proc {
[200, {"Content-Type" => "image/png"}, [""]]
}
end
map "/reset" do
run proc {
current = Hash.new(0)
[200, {"Content-Type" => "text/plain"}, ["success"]]
}
end
map "/ajax/app" do
run proc { |env|
string = env["QUERY_STRING"]
now = current[string] += 1
[200,
{"Content-Type" => "application/json"},
[%{{"count": #{now}, "qs": #{string.inspect}}}]
]
}
end
Jump to Line
Something went wrong with that request. Please try again.