Skip to content

Instantly share code, notes, and snippets.

@mattlenz
Last active October 7, 2015 10:07
Show Gist options
  • Save mattlenz/3148125 to your computer and use it in GitHub Desktop.
Save mattlenz/3148125 to your computer and use it in GitHub Desktop.
Tiny static-site Rack server
require 'rubygems'
require 'bundler/setup'
require 'rack'
@root = File.expand_path(File.dirname(__FILE__))
run Proc.new { |env|
path = Rack::Utils.unescape(env['PATH_INFO'])
index = "#{@root}#{path}/index.html"
if File.exists?(index)
[200, {'Content-Type' => 'text/html'}, [File.read(index)]]
else
Rack::Directory.new(@root).call(env)
end
}
source :rubygems
gem 'rack'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment