pinokiod 3.3.29 → 3.3.31

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 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,24 @@ 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
+ console.log("> Checking port availability", port)
40
+ server.listen(port, (err) => {
41
+ if (err) {
42
+ console.log(">", err)
43
+ resolve(true); // Port is occupied
44
+ } else {
45
+ server.close(); // Close the server immediately after testing
46
+ console.log("> test server started")
47
+ resolve(false); // Port is free
48
+ }
49
+ });
50
+ });
51
+ };
52
+
34
53
  const port_running = async (host, port) => {
35
54
  const timeout = 1000
36
55
  const promise = new Promise((resolve, reject) => {
@@ -206,5 +225,5 @@ const update_env = async (filepath, changes) => {
206
225
  await fs.promises.writeFile(filepath, newval)
207
226
  };
208
227
  module.exports = {
209
- parse_env, log_path, api_path, update_env, parse_env_detail, openfs, port_running, du
228
+ parse_env, log_path, api_path, update_env, parse_env_detail, openfs, port_running, du, is_port_running
210
229
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pinokiod",
3
- "version": "3.3.29",
3
+ "version": "3.3.31",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {
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 running1 = await Util.port_running("localhost", primary_port)
2091
- const running2 = await Util.port_running("127.0.0.1", primary_port)
2092
- const running = running1 || running2
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 })