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
42
43
|
# File 'lib/hyla/commands/serve.rb', line 5
def self.process(args, options)
include WEBrick
my_opts = {}
destination = options[:destination] if self.check_mandatory_option?('-d / --destination', options[:destination])
my_opts[:Port] = options[:port]
my_opts[:BindAddress] = options[:host]
my_opts[:baseurl] = options[:baseurl]
my_opts[:MimeTypes] = self.mime_types
my_opts[:DoNotReverseLookupmy_opts] = true
my_opts[:StartCallback] = start_callback(options[:detach])
my_opts[:AccessLog] = []
my_opts[:Logger] = Log::new([], Log::WARN)
fh_option = WEBrick::Config::FileHandler
fh_option[:NondisclosureName] = ['.ht*','~*']
fh_option[:FancyIndexing] = true
s = HTTPServer.new(my_opts)
s.mount(my_opts[:baseurl],HTTPServlet::FileHandler, destination, fh_option)
Hyla.logger.info "Server address:", "http://#{s.config[:BindAddress]}:#{s.config[:Port]}"
if options[:detach] pid = Process.fork { s.start }
Process.detach(pid)
Hyla.logger.info "Server detached with pid '#{pid}'.", "Run `kill -9 #{pid}' to stop the server."
else t = Thread.new { s.start }
trap("INT") { s.shutdown }
t.join()
end
end
|