lib/kdwatch-app.rb in kdwatch-0.1.1 vs lib/kdwatch-app.rb in kdwatch-0.2.0
- old
+ new
@@ -9,12 +9,14 @@
require "guard"
require "sinatra"
require "kramdown-rfc2629"
require "net/http/persistent"
+host = ENV["KDWATCH_HOST"]
+port = ENV["KDWATCH_PORT"]
-sfn = ENV["KD_WATCH_SRC"]
+sfn = ENV["KDWATCH_SRC"]
fail "No source given" unless sfn
dfn = File.join(File.dirname(sfn), "#{File.basename(sfn, ".*")}.html")
puts dfn
@@ -37,20 +39,23 @@
get "/rfc-local.css" do
# insert local css here
end
File.write(".Guardfile", <<GF)
-guard 'livereload' do
+guard :livereload, :port => #{ENV["KDWATCH_LRPORT"]} do
watch("#{sfn}")
end
GF
rd, _wr = IO.pipe
spawn("guard -G .Guardfile", in: rd, close_others: true)
# wrong: puts settings.port
-url = "http://127.0.0.1:7991"
+host = "localhost" if host == "::" # work around macOS peculiarity
+host = "[#{host}]" if host =~ /:/
+
+url = "http://#{host}:#{port}"
spawn("sleep 5; open #{url} || xdg-open #{url} || echo @@@ Please open #{url}")