Skip to content

Commit

Permalink
fix: 服务器地址为 ipv6 时触发解析
Browse files Browse the repository at this point in the history
  • Loading branch information
geekdada committed May 5, 2020
1 parent c823677 commit aa79c93
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions lib/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { JsonObject } from 'type-fest';
import { parse, format, URL } from 'url';
import URLSafeBase64 from 'urlsafe-base64';
import YAML from 'yaml';
import net from 'net';

import {
HttpNodeConfig,
Expand Down Expand Up @@ -299,7 +300,7 @@ export const getSurgeNodes = function(
`local-port = ${config.localPort}`,
];

if (config.hostnameIp) {
if (config.hostnameIp && config.hostnameIp.length) {
configString.push(...config.hostnameIp.map(item => `addresses = ${item}`));
}

Expand Down Expand Up @@ -396,7 +397,7 @@ export const getSurgeNodes = function(
`local-port = ${config.localPort}`,
];

if (config.hostnameIp) {
if (config.hostnameIp && config.hostnameIp.length) {
configString.push(...config.hostnameIp.map(item => `addresses = ${item}`));
}

Expand Down Expand Up @@ -1362,7 +1363,8 @@ export const lowercaseHeaderKeys = (headers: Record<string, string>) => {
return wsHeaders;
};

export const isIp = (str: string): boolean => /^(?:(?:^|\.)(?:2(?:5[0-5]|[0-4]\d)|1?\d?\d)){4}$/gm.test(str);
// istanbul ignore next
export const isIp = (str: string): boolean => net.isIPv4(str) || net.isIPv6(str);

// istanbul ignore next
export const isNow = () => typeof process.env.NOW_REGION !== 'undefined';
Expand Down

0 comments on commit aa79c93

Please sign in to comment.