Skip to content

Instantly share code, notes, and snippets.

@milep
Created November 7, 2012 16:12
Show Gist options
  • Save milep/4032501 to your computer and use it in GitHub Desktop.
Save milep/4032501 to your computer and use it in GitHub Desktop.
Serve files from folder with webrick
require 'webrick'
include WEBrick # let's import the namespace so
# I don't have to keep typing
# WEBrick:: in this documentation.
def start_webrick(config = {})
# always listen on port 8080
config.update(:Port => 8080)
server = HTTPServer.new(config)
yield server if block_given?
['INT', 'TERM'].each {|signal|
trap(signal) {server.shutdown}
}
server.start
end
start_webrick(:DocumentRoot => '.')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment