Skip to content

Instantly share code, notes, and snippets.

@chooh
Created December 28, 2010 15:48
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save chooh/757345 to your computer and use it in GitHub Desktop.
Save chooh/757345 to your computer and use it in GitHub Desktop.
Simple Rack web server for static files with index.html
# This is the root of our app
@root = File.expand_path(File.join(File.dirname(__FILE__), "www"))
run Proc.new { |env|
# Extract the requested path from the request
req = Rack::Request.new(env)
index_file = File.join(@root, req.path_info, "index.html")
if File.exists?(index_file)
# Rewrite to index
req.path_info += "index.html"
end
# Pass the request to the directory app
Rack::Directory.new(@root).call(env)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment