tt-help-cli-ycl 1.3.3 → 1.3.4
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/package.json +1 -1
- package/src/watch/server.mjs +21 -2
package/package.json
CHANGED
package/src/watch/server.mjs
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import http from 'http';
|
|
2
|
+
import os from 'os';
|
|
3
|
+
|
|
2
4
|
import { readFileSync } from 'fs';
|
|
3
5
|
import { join, dirname } from 'path';
|
|
4
6
|
import { fileURLToPath } from 'url';
|
|
@@ -6,6 +8,18 @@ import { spawn } from 'child_process';
|
|
|
6
8
|
import { createStore } from './data-store.mjs';
|
|
7
9
|
|
|
8
10
|
const __filename = fileURLToPath(import.meta.url);
|
|
11
|
+
|
|
12
|
+
function getLocalIP() {
|
|
13
|
+
const ifaces = os.networkInterfaces();
|
|
14
|
+
for (const name of Object.keys(ifaces)) {
|
|
15
|
+
for (const iface of ifaces[name]) {
|
|
16
|
+
if (iface.family === 'IPv4' && !iface.internal) {
|
|
17
|
+
return iface.address;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
return '0.0.0.0';
|
|
22
|
+
}
|
|
9
23
|
const __dirname = dirname(__filename);
|
|
10
24
|
const publicDir = join(__dirname, 'public');
|
|
11
25
|
|
|
@@ -245,8 +259,11 @@ export function startWatchServer(outputFile, port = 3000) {
|
|
|
245
259
|
}
|
|
246
260
|
});
|
|
247
261
|
|
|
248
|
-
|
|
249
|
-
|
|
262
|
+
const localIP = getLocalIP();
|
|
263
|
+
server.listen(port, '0.0.0.0', () => {
|
|
264
|
+
console.error(`Watch 监控服务已启动:`);
|
|
265
|
+
console.error(` 本地访问: http://127.0.0.1:${port}`);
|
|
266
|
+
console.error(` 局域网访问: http://${localIP}:${port}`);
|
|
250
267
|
_resolve({ server, port });
|
|
251
268
|
});
|
|
252
269
|
});
|
|
@@ -255,3 +272,5 @@ export function startWatchServer(outputFile, port = 3000) {
|
|
|
255
272
|
export function openBrowser(port) {
|
|
256
273
|
spawn('open', [`http://127.0.0.1:${port}`]).on('error', () => {});
|
|
257
274
|
}
|
|
275
|
+
|
|
276
|
+
export { getLocalIP };
|