forked from house9/jquery-iframe-auto-height
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webrick.rb
41 lines (35 loc) · 1.02 KB
/
webrick.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#!/usr/bin/ruby
require 'rubygems'
require 'webrick'
require 'optparse'
# http://ceronio.net/2011/06/nice-web-server-script-to-server-any-directory-using-webrick/
options = {}
# Parse options
optparse = OptionParser.new do|opts|
opts.banner = "Usage: websrv.rb [options]"
options[:port] = 3000
opts.on( '-p', '--port PORT', 'Port Number (default 3000)' ) do |port|
options[:port] = port
end
options[:docroot] = Dir.pwd
opts.on( '-d', '--doc_root PATH', 'Document Root (default current dir)' ) do |docroot|
puts docroot
options[:docroot] = docroot
end
options[:bind] = "localhost"
opts.on( '-b', '--bind HOST', 'Address to bind to (default localhost)' ) do |bind|
options[:bind] = bind
end
opts.on( '-h', '--help', 'Display this screen' ) do
puts opts
exit
end
end
optparse.parse!
# Initialize and start WEBrick
server = WEBrick::HTTPServer.new(
:BindAddress => options[:bind],
:Port => options[:port],
:DocumentRoot => options[:docroot] )
trap "INT" do server.shutdown end
server.start