Skip to content

Instantly share code, notes, and snippets.

@lamdor
Created May 22, 2010 20:01
Show Gist options
  • Select an option

  • Save lamdor/410324 to your computer and use it in GitHub Desktop.

Select an option

Save lamdor/410324 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby -w
require 'rubygems'
require 'rack'
require 'rack/handler/webrick'
require 'optparse'
class App
def self.root
Dir.pwd
end
def self.file_server
@file_server ||= Rack::File.new(root)
end
def self.call(env)
path = env["PATH_INFO"]
file_path = File.join(root, path)
if File.file?(File.join(file_path, "index.html"))
env["PATH_INFO"] = File.join(path, "index.html")
end
file_server.call(env)
end
end
options = {:Port => "8888"}
OptionParser.new do |o|
o.on("-p PORT") { |port| options[:Port] = port }
o.on("-h") { puts o; exit }
o.parse!
end
fork do
sleep 0.2
system "open http://localhost:#{options[:Port]}/"
end
Rack::Handler::WEBrick.run(App, options)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment