lib/jekyll/commands/serve.rb in jekyll-1.5.1 vs lib/jekyll/commands/serve.rb in jekyll-2.0.0.alpha.1
- old
+ new
@@ -8,10 +8,19 @@
destination = options['destination']
FileUtils.mkdir_p(destination)
+ # monkey patch WEBrick using custom 404 page (/404.html)
+ if File.exists?(File.join(destination, '404.html'))
+ WEBrick::HTTPResponse.class_eval do
+ def create_error_page
+ @body = IO.read(File.join(@config[:DocumentRoot], '404.html'))
+ end
+ end
+ end
+
# recreate NondisclosureName under utf-8 circumstance
fh_option = WEBrick::Config::FileHandler
fh_option[:NondisclosureName] = ['.ht*','~*']
s = HTTPServer.new(webrick_options(options))
@@ -21,19 +30,20 @@
Jekyll.logger.info "Server address:", "http://#{s.config[:BindAddress]}:#{s.config[:Port]}"
if options['detach'] # detach the server
pid = Process.fork { s.start }
Process.detach(pid)
- Jekyll.logger.info "Server detatched with pid '#{pid}'.", "Run `kill -9 #{pid}' to stop the server."
+ Jekyll.logger.info "Server detached with pid '#{pid}'.", "Run `kill -9 #{pid}' to stop the server."
else # create a new server thread, then join it with current terminal
t = Thread.new { s.start }
trap("INT") { s.shutdown }
t.join()
end
end
def self.webrick_options(config)
opts = {
+ :DocumentRoot => config['destination'],
:Port => config['port'],
:BindAddress => config['host'],
:MimeTypes => self.mime_types,
:DoNotReverseLookup => true,
:StartCallback => start_callback(config['detach'])