diff --git a/src/kotatsu.cr b/src/kotatsu.cr index 32edffe..1f611c4 100644 --- a/src/kotatsu.cr +++ b/src/kotatsu.cr @@ -1,5 +1,6 @@ # TODO: Write documentation for `Kotatsu` +require "system/user" require "option_parser" require "http/server" require "json" @@ -8,6 +9,7 @@ module Kotatsu VERSION = "0.1.0" CONFIG_DIR = Path.new(Path.home, ".config", "kotatsu") CONFIG_FILE = Path.new(CONFIG_DIR, "config.json") + UNIX_SOCKET_PATH = Path.new("/tmp", "kotatsu.sock") # -- METHODS -- @@ -195,12 +197,17 @@ module Kotatsu webcontent = makeContent(c_title, c_services) + #Checks if socket file exists and deletes it + if File.exists?(UNIX_SOCKET_PATH) == true + File.delete(UNIX_SOCKET_PATH) + end + #Run http server webserv = HTTP::Server.new do |context| context.response.content_type = "text/html" context.response << webcontent end - webaddr = webserv.bind_tcp 8080 + webaddr = webserv.bind_unix(Socket::UNIXAddress.new(UNIX_SOCKET_PATH.to_s)) puts "Started kotatsu webserver on #{webaddr}" webserv.listen -end +end \ No newline at end of file