Created
November 7, 2012 16:12
-
-
Save milep/4032501 to your computer and use it in GitHub Desktop.
Serve files from folder with webrick
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
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