lib/hx/cli.rb in hx-0.19.0 vs lib/hx/cli.rb in hx-0.20.0
- old
+ new
@@ -26,10 +26,11 @@
require 'optparse'
require 'pathname'
require 'tempfile'
require 'webrick'
require 'rack'
+require 'rack/mock'
require 'rack/handler/webrick'
require 'hx/rack/application'
module Hx
module CLI
@@ -103,14 +104,26 @@
real_port = server.config[:Port]
base_url = "http://localhost:#{real_port}/"
server.logger.info "Serving on #{base_url}"
- # reload the site/config, folding in the new base URL
config_file = site.options[:config_file]
- site = Hx::Site.load_file(config_file, :base_url => base_url)
+ mtime = nil
+ site_app = nil
- app = Hx::Rack::Application.new(site, site.options)
+ app = Proc.new { |env|
+ unless site_app and File.mtime(config_file) == mtime
+ # reload the site/config, folding in the new base URL
+ site = Hx::Site.load_file(config_file, :base_url => base_url)
+ mtime = File.mtime(config_file)
+ site_app = Hx::Rack::Application.new(site, site.options)
+ end
+ site_app.call(env)
+ }
+
+ # force application load
+ Rack::MockRequest.new(app).get("/")
+
server.mount('/', ::Rack::Handler::WEBrick, app)
%w(INT TERM).each { |s| trap(s) { server.shutdown } }
server.start
end