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

Commitb5784a1

Browse files
committed
fix: issue 4630
1 parent3d38fbd commitb5784a1

File tree

1 file changed

+18
-45
lines changed

1 file changed

+18
-45
lines changed

‎lib/Server.js‎

Lines changed: 18 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -378,57 +378,30 @@ class Server {
378378
return/^[a-zA-Z][a-zA-Z\d+\-.]*:/.test(URL);
379379
}
380380

381-
/**
382-
*@param {string} gateway
383-
*@returns {string | undefined}
384-
*/
385-
staticfindIp(gateway){
386-
constgatewayIp=ipaddr.parse(gateway);
387-
388-
// Look for the matching interface in all local interfaces.
389-
for(constaddressesofObject.values(os.networkInterfaces())){
390-
for(const{ cidr}of/**@type {NetworkInterfaceInfo[]} */(
391-
addresses
392-
)){
393-
constnet=ipaddr.parseCIDR(/**@type {string} */(cidr));
394-
395-
if(
396-
net[0]&&
397-
net[0].kind()===gatewayIp.kind()&&
398-
gatewayIp.match(net)
399-
){
400-
returnnet[0].toString();
401-
}
402-
}
403-
}
404-
}
405-
406381
/**
407382
*@param {"v4" | "v6"} family
408383
*@returns {Promise<string | undefined>}
409384
*/
410385
staticasyncinternalIP(family){
411-
try{
412-
const{ gateway}=awaitrequire("default-gateway")[family]();
413-
414-
returnServer.findIp(gateway);
415-
}catch{
416-
// ignore
417-
}
418-
}
419-
420-
/**
421-
*@param {"v4" | "v6"} family
422-
*@returns {string | undefined}
423-
*/
424-
staticinternalIPSync(family){
425-
try{
426-
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+
});
427403

428-
returnServer.findIp(gateway);
429-
}catch{
430-
// ignore
431-
}
404+
returnhost;
432405
}
433406

434407
/**

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp