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
|
# File 'lib/jekyll/commands/serve.rb', line 5
def self.process(options)
require 'webrick'
include WEBrick
destination = options['destination']
FileUtils.mkdir_p(destination)
mime_types_file = File.expand_path('../mime.types', File.dirname(__FILE__))
mime_types = WEBrick::HTTPUtils::load_mime_types(mime_types_file)
fh_option = WEBrick::Config::FileHandler
fh_option[:NondisclosureName] = ['.ht*','~*']
s = HTTPServer.new(
:Port => options['port'],
:BindAddress => options['host'],
:MimeTypes => mime_types
)
s.mount(options['baseurl'], HTTPServlet::FileHandler, destination, fh_option)
if options['detach'] pid = Process.fork {s.start}
Process.detach(pid)
pid
else t = Thread.new { s.start }
trap("INT") { s.shutdown }
t.join()
end
end
|