Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Cannot retrieve contributors at this time

31 lines (27 sloc) 0.659 kb
# 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 { }
Jump to Line
Something went wrong with that request. Please try again.