diff --git a/lib/webrick/simple.rb b/lib/webrick/simple.rb new file mode 100644 index 0000000..8aba549 --- /dev/null +++ b/lib/webrick/simple.rb @@ -0,0 +1,25 @@ +require 'webrick' + +### +# Simple WEBrick file server. Usage: +# +# Start the file server, serving the files in the current directory +# +# $ ruby -rwebrick/simple -e start +# +# Start the file server, serving the files in the current directory on +# port 5000. +# +# $ ruby -rwebrick/simple -e start 5000 +# +# Start the file server, serving the files in /tmp on port 5000. +# +# $ ruby -rwebrick/simple -e start 5000 /tmp + +def start + port = ARGV.fetch 0, 0 + root = ARGV.fetch 1, '.' + s = WEBrick::HTTPServer.new(:DocumentRoot => root, :Port => port) + trap('INT') { s.shutdown } + s.start +end