Skip to content

Commit

Permalink
Merge pull request #115 from brianhuster/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
brianhuster authored Oct 11, 2024
2 parents f986f57 + e53d816 commit 104cfdb
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
2 changes: 0 additions & 2 deletions lua/livepreview/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,9 @@ function M.preview_file(filepath, port)
server:start("127.0.0.1", port, function(client)
if M.utils.supported_filetype(filepath) == 'html' then
M.server.websocket.send_json(client, { type = "reload" })
print("Send reload message")
else
local content = M.utils.uv_read_file(filepath)
M.server.websocket.send_json(client, { type = "update", content = content })
print("Send update message")
end
end)
end)
Expand Down
8 changes: 7 additions & 1 deletion lua/livepreview/server/Server.lua
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,13 @@ end
--- @param func function(client)|nil: function to call when when there is a change in the watched directory
--- @param client uv_tcp_t: uv_tcp client
function Server:start(ip, port, func)
self.server:bind(ip, port)
local result = self.server:bind(ip, port)
if result == 0 then
print(string.format(
"Note : If live-preview doesn't work, please check and stop the process that uses the port %d",
port))
return
end
self.server:listen(128, function(err)
if err then
print("Listen error: " .. err)
Expand Down

0 comments on commit 104cfdb

Please sign in to comment.