Skip to content

Instantly share code, notes, and snippets.

@chendo
Created February 22, 2010 22:55
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chendo/311624 to your computer and use it in GitHub Desktop.
Save chendo/311624 to your computer and use it in GitHub Desktop.
# Rack::SimpleServer
#
# a small rack app that acts like a basic HTTP server
# github.com/chendo
#
# Options:
# * :root => directory to expose
# e.g., use Rack::SimpleServer, :root => 'pub'
module Rack
class SimpleServer
def initialize(app, options = {})
@app = app
root = options[:root] || 'public'
@index = Dir.chdir(root) do
Dir['*'].grep(/^index\.html?$/).first
end
@file_server = ::Rack::File.new(root)
end
def call(env)
path = env['PATH_INFO']
env['PATH_INFO'] = @index if path == '/' && @index
@file_server.call(env)
end
end
end
use Rack::SimpleServer
run proc { }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment