Created
February 22, 2010 22:55
-
-
Save chendo/311624 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
# 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