@thzero/library_server 0.14.6 → 0.14.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/boot/index.js +4 -2
- package/package.json +2 -3
- package/utility/internalIp/index.js +49 -0
package/boot/index.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import internalIp from 'internal-ip';
|
|
1
|
+
// import internalIp from 'internal-ip';
|
|
2
|
+
// Until author fixes the issue with version 7+
|
|
3
|
+
import {internalIpV6, internalIpV4} from '@thzero/library_server/utility/internalIp';
|
|
2
4
|
|
|
3
5
|
import { createTerminus } from '@godaddy/terminus';
|
|
4
6
|
|
|
@@ -105,7 +107,7 @@ class BootMain {
|
|
|
105
107
|
await listen(this.port);
|
|
106
108
|
this.address = serverHttp.address() ? serverHttp.address().address : null;
|
|
107
109
|
if (this.address === '::')
|
|
108
|
-
this.address = await
|
|
110
|
+
this.address = await internalIpV4();
|
|
109
111
|
|
|
110
112
|
await this._initServer(serverHttp);
|
|
111
113
|
|
package/package.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@thzero/library_server",
|
|
3
|
-
"version": "0.14.
|
|
3
|
+
"version": "0.14.7",
|
|
4
4
|
"version_major": 0,
|
|
5
5
|
"version_minor": 14,
|
|
6
|
-
"version_patch":
|
|
6
|
+
"version_patch": 7,
|
|
7
7
|
"version_date": "10/20/2021",
|
|
8
8
|
"description": "An opinionated library of common functionality to bootstrap a Koa based API application using MongoDb and Firebase.",
|
|
9
9
|
"author": "thZero",
|
|
@@ -34,7 +34,6 @@
|
|
|
34
34
|
"dayjs-plugin-utc": "^0.1.2",
|
|
35
35
|
"easy-rbac": "^3.1.1",
|
|
36
36
|
"esm": "^3.2.25",
|
|
37
|
-
"internal-ip": "^7.0.0",
|
|
38
37
|
"koa": "^2.13.4",
|
|
39
38
|
"koa-body": "^4.2.0",
|
|
40
39
|
"koa-helmet": "^6.1.0",
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import {networkInterfaces} from 'os';
|
|
2
|
+
import defaultGateway from 'default-gateway';
|
|
3
|
+
import ip from 'ipaddr.js';
|
|
4
|
+
|
|
5
|
+
function findIp(gateway) {
|
|
6
|
+
const gatewayIp = ip.parse(gateway);
|
|
7
|
+
|
|
8
|
+
// Look for the matching interface in all local interfaces.
|
|
9
|
+
for (const addresses of Object.values(networkInterfaces())) {
|
|
10
|
+
for (const {cidr} of addresses) {
|
|
11
|
+
const net = ip.parseCIDR(cidr);
|
|
12
|
+
|
|
13
|
+
// eslint-disable-next-line unicorn/prefer-regexp-test
|
|
14
|
+
if (net[0] && net[0].kind() === gatewayIp.kind() && gatewayIp.match(net)) {
|
|
15
|
+
return net[0].toString();
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
async function async(family) {
|
|
22
|
+
try {
|
|
23
|
+
const {gateway} = await defaultGateway[family]();
|
|
24
|
+
return findIp(gateway);
|
|
25
|
+
} catch {}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function sync(family) {
|
|
29
|
+
try {
|
|
30
|
+
const {gateway} = defaultGateway[family].sync();
|
|
31
|
+
return findIp(gateway);
|
|
32
|
+
} catch {}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export async function internalIpV6() {
|
|
36
|
+
return async('v6');
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export async function internalIpV4() {
|
|
40
|
+
return async('v4');
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export function internalIpV6Sync() {
|
|
44
|
+
return sync('v6');
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export function internalIpV4Sync() {
|
|
48
|
+
return sync('v4');
|
|
49
|
+
}
|