Skip to content

Commit

Permalink
fix: #76
Browse files Browse the repository at this point in the history
  • Loading branch information
hubcarl committed Jun 10, 2020
1 parent c4dda88 commit a768ca4
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 17 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "easywebpack",
"version": "4.12.7",
"version": "4.12.8",
"description": "基于 Webpack 的前端构建工程化解决方案",
"keywords": [
"webpack",
Expand Down
21 changes: 21 additions & 0 deletions test/utils.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
'use strict';
const expect = require('chai').expect;
const utils = require('../utils/utils');

describe('utils.test.js', () => {
before(() => {});

after(() => {});

beforeEach(() => {});

afterEach(() => {});

describe('#utils test', () => {
it('should ip test', () => {
const ip = utils.getIp();
expect(ip).to.be.not.equal('127.0.0.1');
expect(ip.split('.').length).to.be.equal(4);
});
});
});
27 changes: 11 additions & 16 deletions utils/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -331,28 +331,23 @@ utils.loadNodeModules = isCache => {
utils.getIp = position => {
const interfaces = os.networkInterfaces();
const ips = [];

if (interfaces.en0) {
for (let i = 0; i < interfaces.en0.length; i++) {
if (interfaces.en0[i].family === 'IPv4') {
ips.push(interfaces.en0[i].address);
}
}
}
if (interfaces.en1) {
for (let i = 0; i < interfaces.en1.length; i++) {
if (interfaces.en1[i].family === 'IPv4') {
ips.push(interfaces.en1[i].address);
}
const ens = [interfaces.en0, interfaces.en1, interfaces.eth0, interfaces.eth1];
ens.forEach(en => {
if (Array.isArray(en)) {
en.forEach(item => {
if (item.family === 'IPv4') {
ips.push(item.address);
}
});
}
}
});
if (position > 0 && position <= ips.length) {
return ips[position - 1];
} else if (ips.length) {
}
if (ips.length) {
return ips[0];
}
return '127.0.0.1';

};

utils.getHost = port => {
Expand Down

0 comments on commit a768ca4

Please sign in to comment.