pinokiod 3.3.29 → 3.3.30
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 +17 -1
- package/package.json +1 -1
- package/server/index.js +4 -3
package/kernel/util.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
const fs = require('fs')
|
|
2
|
+
const http = require('http');
|
|
2
3
|
const os = require('os')
|
|
3
4
|
const net = require('node:net')
|
|
4
5
|
const path = require('path')
|
|
@@ -31,6 +32,21 @@ const du = async (folderpath) => {
|
|
|
31
32
|
console.log("totalSize", totalSize)
|
|
32
33
|
return totalSize;
|
|
33
34
|
}
|
|
35
|
+
|
|
36
|
+
const is_port_running = async (port) => {
|
|
37
|
+
return new Promise((resolve) => {
|
|
38
|
+
const server = http.createServer();
|
|
39
|
+
server.listen(port, (err) => {
|
|
40
|
+
if (err) {
|
|
41
|
+
resolve(false); // Port is occupied
|
|
42
|
+
} else {
|
|
43
|
+
server.close(); // Close the server immediately after testing
|
|
44
|
+
resolve(true); // Port is free
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
});
|
|
48
|
+
};
|
|
49
|
+
|
|
34
50
|
const port_running = async (host, port) => {
|
|
35
51
|
const timeout = 1000
|
|
36
52
|
const promise = new Promise((resolve, reject) => {
|
|
@@ -206,5 +222,5 @@ const update_env = async (filepath, changes) => {
|
|
|
206
222
|
await fs.promises.writeFile(filepath, newval)
|
|
207
223
|
};
|
|
208
224
|
module.exports = {
|
|
209
|
-
parse_env, log_path, api_path, update_env, parse_env_detail, openfs, port_running, du
|
|
225
|
+
parse_env, log_path, api_path, update_env, parse_env_detail, openfs, port_running, du, is_port_running
|
|
210
226
|
}
|
package/package.json
CHANGED
package/server/index.js
CHANGED
|
@@ -2087,9 +2087,10 @@ class Server {
|
|
|
2087
2087
|
} else {
|
|
2088
2088
|
const primary_port = 80
|
|
2089
2089
|
const secondary_port = 42000
|
|
2090
|
-
const
|
|
2091
|
-
const
|
|
2092
|
-
const
|
|
2090
|
+
const running = await Util.is_port_running(primary_port)
|
|
2091
|
+
// const running1 = await Util.port_running("localhost", primary_port)
|
|
2092
|
+
// const running2 = await Util.port_running("127.0.0.1", primary_port)
|
|
2093
|
+
// const running = running1 || running2
|
|
2093
2094
|
const available = !running
|
|
2094
2095
|
//const available = await portfinder.isAvailablePromise({ host: "0.0.0.0", port: primary_port })
|
|
2095
2096
|
console.log("check available", { primary_port, available })
|