Skip to content

Instantly share code, notes, and snippets.

@thechrisoshow
Created July 15, 2010 13:48
Show Gist options
  • Save thechrisoshow/476957 to your computer and use it in GitHub Desktop.
Save thechrisoshow/476957 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
require 'webrick'
include WEBrick
require 'erb'
s = HTTPServer.new( :Port => 3000,:DocumentRoot => Dir::pwd + '/' + (ARGV[0] || '.'))
class ErbServlet < HTTPServlet::AbstractServlet
def do_GET(req, response)
File.open(ARGV[0],'r') do |f|
@template = ERB.new(f.read)
end
response.body = @template.result(binding)
response['Content-Type'] = "text/html"
end
end
s.mount("/", ErbServlet)
trap("INT"){
s.shutdown
}
s.start
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment