diff --git a/.autod.conf.js b/.autod.conf.js index c5861d4..2a86e06 100644 --- a/.autod.conf.js +++ b/.autod.conf.js @@ -7,7 +7,6 @@ module.exports = { 'test', ], dep: [ - 'address', 'formstream', 'moment', 'nounou', diff --git a/common/utils.js b/common/utils.js index bd15437..8bf449d 100644 --- a/common/utils.js +++ b/common/utils.js @@ -1,11 +1,22 @@ 'use strict'; const os = require('os'); -const address = require('address'); const crypto = require('crypto'); const { promisify } = require('util'); const path = require('path'); +exports.getIp = function getIp() { + const interfaces = os.networkInterfaces(); + for (const interfaceItems of Object.values(interfaces)) { + for (const item of interfaceItems) { + if (item.family === 'IPv4' && !item.internal) { + return item.address; + } + } + } + return '127.0.0.1'; +}; + exports.regularWsServer = function(server) { return server.startsWith('ws://') || server.startsWith('wss://'); }; @@ -22,7 +33,7 @@ exports.getAgentId = function(customAgent, ipMode) { if (!ipMode) { return `${os.hostname()}`; } - return `${address.ip()}::${os.hostname()}`; + return `${exports.getIp()}::${os.hostname()}`; }; exports.sign = function(message, secret) { diff --git a/package.json b/package.json index 12aff90..cbbd467 100644 --- a/package.json +++ b/package.json @@ -41,7 +41,6 @@ }, "homepage": "https://github.com/X-Profiler/xtransit#readme", "dependencies": { - "address": "^1.1.2", "form-data": "^4.0.0", "moment": "^2.28.0", "nounou": "^1.2.1", diff --git a/test/fixtures/files/package-lock.json b/test/fixtures/files/package-lock.json index c381cb3..7fa8383 100644 --- a/test/fixtures/files/package-lock.json +++ b/test/fixtures/files/package-lock.json @@ -551,11 +551,6 @@ "integrity": "sha1-KUrbcbVzmLBoABXwo4xWPuHbU4Q=", "dev": true }, - "address": { - "version": "1.1.2", - "resolved": "https://registry.npm.taobao.org/address/download/address-1.1.2.tgz", - "integrity": "sha1-vxEWycdYxRt6kz0pa3LCIe2UKLY=" - }, "agent-base": { "version": "4.3.0", "resolved": "https://registry.npm.taobao.org/agent-base/download/agent-base-4.3.0.tgz?cache=0&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fagent-base%2Fdownload%2Fagent-base-4.3.0.tgz", @@ -2541,7 +2536,6 @@ "resolved": "https://registry.npm.taobao.org/utility/download/utility-0.1.11.tgz?cache=0&sync_timestamp=1574243892588&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Futility%2Fdownload%2Futility-0.1.11.tgz", "integrity": "sha1-/eYM+bTkdRlHoM9dEEzik2ciZxU=", "requires": { - "address": ">=0.0.1" } } } diff --git a/test/fixtures/files/package.json b/test/fixtures/files/package.json index b059fcd..99d80ca 100644 --- a/test/fixtures/files/package.json +++ b/test/fixtures/files/package.json @@ -40,7 +40,6 @@ }, "homepage": "https://github.com/X-Profiler/xtransit#readme", "dependencies": { - "address": "^1.1.2", "formstream": "^1.1.0", "moment": "^2.26.0", "nounou": "^1.2.1", diff --git a/test/fixtures/files/test_error b/test/fixtures/files/test_error new file mode 100644 index 0000000..e69de29