Skip to content

Instantly share code, notes, and snippets.

@bbttxu
Created June 4, 2011 15:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bbttxu/1007976 to your computer and use it in GitHub Desktop.
Save bbttxu/1007976 to your computer and use it in GitHub Desktop.
require 'rubygems'
require 'rack'
require 'rack-legacy'
require 'rack-rewrite'
require 'rack/tidy'
# flipped, returning late rather than first to get around LocalJumpError
# http://blog.jayfields.com/2007/03/ruby-localjumperror-workaround.html#4379157363252949431
INDEXES = ['index.cgi', 'index.php', 'index.html']
use Rack::Rewrite do
rewrite %r{(.*/$)}, lambda {|match, rack_env|
served_file = rack_env['PATH_INFO']
INDEXES.each do |index|
if File.exists?(File.join(Dir.getwd, rack_env['PATH_INFO'], index))
served_file = rack_env['PATH_INFO'] + index
end
end
served_file
}
end
use Rack::Tidy
use Rack::Legacy::Php, Dir.getwd
use Rack::Legacy::Cgi, Dir.getwd
run Rack::File.new Dir.getwd
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment