Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitdab3db4

Browse files
committed
fix: issue 4630
1 parent53eefda commitdab3db4

File tree

1 file changed

+18
-46
lines changed

1 file changed

+18
-46
lines changed

‎lib/Server.js‎

Lines changed: 18 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
"use strict";
22

33
constos=require("os");
4-
const{ networkInterfaces}=require("node:os");
54
constpath=require("path");
65
consturl=require("url");
76
constutil=require("util");
@@ -379,57 +378,30 @@ class Server {
379378
return/^[a-zA-Z][a-zA-Z\d+\-.]*:/.test(URL);
380379
}
381380

382-
/**
383-
*@returns {string | undefined}
384-
*/
385-
staticasyncfindIp(){
386-
387-
// const gatewayIp = ipaddr.parse(gateway);
388-
//
389-
// // Look for the matching interface in all local interfaces.
390-
// for (const addresses of Object.values(os.networkInterfaces())) {
391-
// for (const { cidr } of /**@type {NetworkInterfaceInfo[]} */ (
392-
// addresses
393-
// )) {
394-
// const net = ipaddr.parseCIDR(/**@type {string} */ (cidr));
395-
//
396-
// if (
397-
// net[0] &&
398-
// net[0].kind() === gatewayIp.kind() &&
399-
// gatewayIp.match(net)
400-
// ) {
401-
// return net[0].toString();
402-
// }
403-
// }
404-
// }
405-
}
406-
407381
/**
408382
*@param {"v4" | "v6"} family
409383
*@returns {Promise<string | undefined>}
410384
*/
411385
staticasyncinternalIP(family){
412-
try{
413-
const{ gateway}=awaitrequire("default-gateway")[family]();
414-
415-
returnServer.findIp(gateway);
416-
}catch{
417-
// ignore
418-
}
419-
}
420-
421-
/**
422-
*@param {"v4" | "v6"} family
423-
*@returns {string | undefined}
424-
*/
425-
staticinternalIPSync(family){
426-
try{
427-
const{ gateway}=require("default-gateway")[family].sync();
386+
lethost;
387+
Object.values(os.networkInterfaces())
388+
.flatMap((networks)=>networks??[])
389+
.filter(
390+
(network)=>
391+
network&&
392+
network.address&&
393+
network.family===`IP${family}`&&
394+
// I'm not sure whether I need to only filter to internal IP address
395+
network.internal===true,
396+
)
397+
.forEach((network)=>{
398+
host=network.address;
399+
if(host.includes(":")){
400+
host=`[${host}]`;
401+
}
402+
});
428403

429-
returnServer.findIp(gateway);
430-
}catch{
431-
// ignore
432-
}
404+
returnhost;
433405
}
434406

435407
/**

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp