diff options
| author | RblSb <msrblsb@gmail.com> | 2021-07-04 03:59:50 +0300 |
|---|---|---|
| committer | RblSb <msrblsb@gmail.com> | 2021-07-05 17:04:25 +0300 |
| commit | ede45cea8706eb8540e466df9861c2af8ebf9c44 (patch) | |
| tree | 74a20a6f082173378f918b48b08542881f31749a /src/server/Utils.hx | |
| parent | 265b3e1fb56bb0e5f797b3b35227a616b108a0c3 (diff) | |
Reformat
Diffstat (limited to 'src/server/Utils.hx')
| -rw-r--r-- | src/server/Utils.hx | 15 |
1 files changed, 6 insertions, 9 deletions
diff --git a/src/server/Utils.hx b/src/server/Utils.hx index bab6300..9aa0d66 100644 --- a/src/server/Utils.hx +++ b/src/server/Utils.hx @@ -1,18 +1,17 @@ package server; -import js.node.url.URL; -import js.node.Https; import js.node.Http; +import js.node.Https; import js.node.Os; +import js.node.url.URL; import sys.FileSystem; class Utils { - public static function ensureDir(path:String):Void { if (!FileSystem.exists(path)) FileSystem.createDirectory(path); } - public static function isPortFree(port:Int, callback:(free:Bool)->Void):Void { + public static function isPortFree(port:Int, callback:(isFree:Bool) -> Void):Void { final server = Http.createServer(); final timeout = 1000; var status = false; @@ -22,7 +21,7 @@ class Utils { status = false; server.close(); }); - server.once("timeout", function () { + server.once("timeout", function() { status = false; trace('Timeout (${timeout}ms) occurred waiting for port $port to be available'); server.close(); @@ -35,7 +34,7 @@ class Utils { server.listen(port); } - public static function getGlobalIp(callback:(ip:String)->Void):Void { + public static function getGlobalIp(callback:(ip:String) -> Void):Void { function onError(e):Void { trace("Warning: connection error, server is local."); callback("127.0.0.1"); @@ -51,8 +50,7 @@ class Utils { final data = new StringBuf(); r.on("data", chunk -> data.add(chunk)); r.on("end", _ -> callback(data.toString())); - }).on("error", onError) - .on("timeout", onError); + }).on("error", onError).on("timeout", onError); } public static function getLocalIp():String { @@ -89,5 +87,4 @@ class Utils { arr[n] = a; } } - } |
