78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
|
# File 'lib/zwite.rb', line 78
def run_server
require "webrick"
mime_types = WEBrick::HTTPUtils::DefaultMimeTypes
mime_types.store("js", "application/javascript")
server_callback = Proc.new do |request|
@site.build
end
server = WEBrick::HTTPServer.new(
:AccessLog => [nil, nil],
:Logger => WEBrick::Log.new("/dev/null"),
:Port => @options["server_port"],
:DirectoryIndex => ["index.html","index.htm", "index.xml"],
:MimeTypes => mime_types,
)
server.mount("/", WEBrick::HTTPServlet::FileHandler, @site.output_path,
:FancyIndexing => true,
:HandlerCallback => server_callback
)
["INT", "TERM"].each do |signal|
trap(signal) do
server.shutdown
exit(1)
end
end
server_thread = Thread.new do
puts "Running Server: localhost:#{@options["server_port"]}"
server.start
end
server_thread.join
end
|