pinokiod 3.3.31 → 3.3.33
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/kernel/util.js +19 -12
- package/package.json +1 -1
- package/server/index.js +3 -2
package/kernel/util.js
CHANGED
|
@@ -33,20 +33,27 @@ const du = async (folderpath) => {
|
|
|
33
33
|
return totalSize;
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
-
const
|
|
36
|
+
const is_port_available = async (port) => {
|
|
37
37
|
return new Promise((resolve) => {
|
|
38
38
|
const server = http.createServer();
|
|
39
39
|
console.log("> Checking port availability", port)
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
40
|
+
try {
|
|
41
|
+
server.listen(port, (err) => {
|
|
42
|
+
if (err) {
|
|
43
|
+
console.log("> [1 port not available]", err)
|
|
44
|
+
resolve(false); // Port is occupied
|
|
45
|
+
} else {
|
|
46
|
+
console.log("> [2 port available] test server started. closing test server now.")
|
|
47
|
+
server.close(() => {
|
|
48
|
+
console.log("> Test server closed.")
|
|
49
|
+
resolve(true); // Port is free
|
|
50
|
+
}); // Close the server immediately after testing
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
} catch (e) {
|
|
54
|
+
console.log("> [3 port not available]", err)
|
|
55
|
+
resolve(false) // port not available
|
|
56
|
+
}
|
|
50
57
|
});
|
|
51
58
|
};
|
|
52
59
|
|
|
@@ -225,5 +232,5 @@ const update_env = async (filepath, changes) => {
|
|
|
225
232
|
await fs.promises.writeFile(filepath, newval)
|
|
226
233
|
};
|
|
227
234
|
module.exports = {
|
|
228
|
-
parse_env, log_path, api_path, update_env, parse_env_detail, openfs, port_running, du,
|
|
235
|
+
parse_env, log_path, api_path, update_env, parse_env_detail, openfs, port_running, du, is_port_available
|
|
229
236
|
}
|
package/package.json
CHANGED
package/server/index.js
CHANGED
|
@@ -2087,11 +2087,12 @@ class Server {
|
|
|
2087
2087
|
} else {
|
|
2088
2088
|
const primary_port = 80
|
|
2089
2089
|
const secondary_port = 42000
|
|
2090
|
-
const
|
|
2090
|
+
const available = await Util.is_port_available(primary_port)
|
|
2091
|
+
//const running = await Util.is_port_running(primary_port)
|
|
2091
2092
|
// const running1 = await Util.port_running("localhost", primary_port)
|
|
2092
2093
|
// const running2 = await Util.port_running("127.0.0.1", primary_port)
|
|
2093
2094
|
// const running = running1 || running2
|
|
2094
|
-
const available = !running
|
|
2095
|
+
// const available = !running
|
|
2095
2096
|
//const available = await portfinder.isAvailablePromise({ host: "0.0.0.0", port: primary_port })
|
|
2096
2097
|
console.log("check available", { primary_port, available })
|
|
2097
2098
|
if (available) {
|