lib/hx/cli.rb in hx-0.10.0 vs lib/hx/cli.rb in hx-0.11.0
- old
+ new
@@ -84,14 +84,11 @@
unless options.config_file
raise RuntimeError, "No #{DEFAULT_CONFIG_FILENAME} found"
end
end
- site = nil
- options.config_file.open("r") do |stream|
- site = Hx::Site.load(stream, options.config_file)
- end
+ site = Hx::Site.load_file(options.config_file)
subcommand = args.shift || "upgen"
method_name = "cmd_#{subcommand}".intern
begin
m = method(method_name)
@@ -102,12 +99,19 @@
end
def self.cmd_serve(site, port=nil)
server = WEBrick::HTTPServer.new({:Port => port || 0})
real_port = server.config[:Port]
+
base_url = "http://localhost:#{real_port}/"
server.logger.info "Serving on #{base_url}"
- site.options[:base_url] = base_url
+
+ # reload the site/config, folding in the new base URL
+ config_file = site.options[:config_file]
+ raw_config = File.open(config_file, 'r') { |s| YAML.load(s) }
+ (raw_config['options'] ||= {})['base_url'] = base_url
+ site = Hx::Site.load_raw(raw_config, config_file)
+
app = Hx::Rack::Application.new(site, site.options)
server.mount('/', ::Rack::Handler::WEBrick, app)
%w(INT TERM).each { |s| trap(s) { server.shutdown } }
server.start
end