Created
July 24, 2013 17:28
-
-
Save natew/6072646 to your computer and use it in GitHub Desktop.
Turn any directory into a simple rack server to serve static files
This file contains 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
# This is the root of our app | |
@root = File.expand_path(File.dirname(__FILE__)) | |
run Proc.new { |env| | |
# Extract the requested path from the request | |
path = Rack::Utils.unescape(env['PATH_INFO']) | |
index_file = @root + "#{path}index.html" | |
if File.exists?(index_file) | |
# Return the index | |
[200, {'Content-Type' => 'text/html'}, [File.read(index_file)]] | |
else | |
# Pass the request to the directory app | |
Rack::Directory.new(@root).call(env) | |
end | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment