@thzero/library_server 0.14.3 → 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 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 internalIp.v4();
110
+ this.address = await internalIpV4();
109
111
 
110
112
  await this._initServer(serverHttp);
111
113
 
@@ -132,7 +134,9 @@ class BootMain {
132
134
  let obj;
133
135
  const results = [];
134
136
  for (const plugin of args) {
135
- obj = new plugin();
137
+ obj = plugin;
138
+ if (!this._isObject(obj))
139
+ obj = new plugin();
136
140
  obj.init(this._appConfig, injector);
137
141
  results.push(obj);
138
142
  }
@@ -353,6 +357,10 @@ class BootMain {
353
357
  _initShutdown() {
354
358
  }
355
359
 
360
+ _isObject(objValue) {
361
+ return objValue && typeof objValue === 'object';
362
+ }
363
+
356
364
  _registerServicesLogger(key, service) {
357
365
  this._injectService(key, service);
358
366
  this.loggerServiceI.register(key);
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "@thzero/library_server",
3
- "version": "0.14.3",
3
+ "version": "0.14.7",
4
4
  "version_major": 0,
5
5
  "version_minor": 14,
6
- "version_patch": 3,
7
- "version_date": "10/12/2021",
6
+ "version_patch": 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",
10
10
  "license": "MIT",
@@ -34,14 +34,13 @@
34
34
  "dayjs-plugin-utc": "^0.1.2",
35
35
  "easy-rbac": "^3.1.1",
36
36
  "esm": "^3.2.25",
37
- "internal-ip": "^6.2.0",
38
- "koa": "^2.13.3",
37
+ "koa": "^2.13.4",
39
38
  "koa-body": "^4.2.0",
40
39
  "koa-helmet": "^6.1.0",
41
40
  "koa-static": "^5.0.0"
42
41
  },
43
42
  "devDependencies": {
44
- "@thzero/library_cli": "^0.13.20"
43
+ "@thzero/library_cli": "^0.13.21"
45
44
  },
46
45
  "peerDependencies": {
47
46
  "@thzero/library_common": "^0.14",
@@ -50,10 +49,10 @@
50
49
  "@babel/plugin-proposal-class-properties": "^7.14.5",
51
50
  "@babel/preset-env": "^7.15.8",
52
51
  "babel-loader": "^8.2.2",
53
- "eslint": "^8.0.0",
52
+ "eslint": "^8.0.1",
54
53
  "eslint-plugin-node": "^11.1.0",
55
- "pino-pretty": "^7.0.1",
56
- "webpack": "^5.58.1",
57
- "webpack-cli": "^4.9.0"
54
+ "pino-pretty": "^7.1.0",
55
+ "webpack": "^5.59.0",
56
+ "webpack-cli": "^4.9.1"
58
57
  }
59
58
  }
@@ -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
+ }