-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmini_server.rb
More file actions
37 lines (32 loc) · 904 Bytes
/
mini_server.rb
File metadata and controls
37 lines (32 loc) · 904 Bytes
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
#!/usr/bin/env ruby
require 'webrick'
require 'optparse'
include WEBrick # let's import the namespace so
# I don't have to keep typing
# WEBrick:: in this documentation.
options = {Port:8080, DocumentRoot:'./'}
optparser = OptionParser.new do |opts|
opts.banner = "Usage: #{File.basename(__FILE__)} [options]"
opts.on("-p", "--port port_num", "Specify Port Number") do |v|
options[:Port]=v
end
opts.on("-d", "--docroot path", "Specify Document Root Folder") do |v|
options[:DocumentRoot]=v
end
end
def start_webrick(config = {})
# always listen on port 8080
server = HTTPServer.new(config)
yield server if block_given?
['INT', 'TERM'].each {|signal|
trap(signal) {server.shutdown}
}
server.start
end
#begin
optparser.parse!(ARGV)
puts options
start_webrick(options)
#rescue Exception=>e
puts optparser.to_s
#end