diff --git a/src/kemal-watcher.cr b/src/kemal-watcher.cr index afa150b..41c8403 100644 --- a/src/kemal-watcher.cr +++ b/src/kemal-watcher.cr @@ -4,15 +4,14 @@ require "secure_random" require "./kemal-watcher/*" - module Kemal SOCKETS = [] of HTTP::WebSocket WEBSOCKETPATH = SecureRandom.hex 4 # Uses Watcher.watch shard to guard files def self.watcher(files) - puts " Your KemalBot is vigilant. beep-boop..." spawn do + puts " Your KemalBot is vigilant. beep-boop..." watch files do |event| event.on_change do |files| files.each do |file, time| @@ -24,14 +23,6 @@ module Kemal end end - # Handle change when event.on_change and - # send reload message to all clients - def self.handle_change - SOCKETS.each do |socket| - socket.send "reload" - end - end - # Watch files and add WatcherHandler to Kemal handlers def self.watch(files) if Kemal.config.env == "production" || ENV["KEMAL_ENV"]? == "production" diff --git a/src/kemal-watcher/watcher_handler.cr b/src/kemal-watcher/watcher_handler.cr index 51bba6b..d50594c 100644 --- a/src/kemal-watcher/watcher_handler.cr +++ b/src/kemal-watcher/watcher_handler.cr @@ -8,6 +8,14 @@ module Kemal # end # end + # Handle change when event.on_change and + # send reload message to all clients + def self.handle_change + SOCKETS.each do |socket| + socket.send "reload" + end + end + # Instead of Kemal::Handler I'm using a filter handler # to check content_type == "text/html" # However, http://kemalcr.com/docs/filters/ says: