@autofleet/node-common 1.0.1 → 1.0.2

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/README.md CHANGED
@@ -0,0 +1,37 @@
1
+ # AutoFleet Node Common
2
+ This respostory is made in order have as much of common code as we can.
3
+
4
+ Each line of code used in wrriten in this repo will be used in the enetire AutoFleet system.
5
+
6
+ Make sure you have:
7
+ * Tests
8
+ * Docs
9
+
10
+ ## Network
11
+ Server 2 Servers communication.
12
+
13
+ Implement:
14
+ * Retriving service urls from environment
15
+ * Retry - TBD
16
+ * Caching - TBD
17
+ * Syntatic response for fail - TBD
18
+ * Circuit Breaking - TBD
19
+
20
+ The API is just like [axios](https://github.com/axios/axios) api but the creation of new instance **must** have either `serviceName` or `serviceUrl` in options.
21
+
22
+ In case `serviceName` used the constractor will look for an environment varible with the the name `SERVICE_URL_<SERVICE_NAME>`.
23
+
24
+ For Example:
25
+ ```
26
+ const { Network } = require('@autofleet/node-common');
27
+
28
+ n = new Network({ serviceName: 'TEST' });
29
+
30
+ n.get('/posts/1');
31
+ ```
32
+ .env file:
33
+ ```
34
+ SERVICE_URL_TEST=https://jsonplaceholder.typicode.com
35
+ ```
36
+
37
+ To learn more [click here](https://blog.risingstack.com/designing-microservices-architecture-for-failure/).
@@ -22,10 +22,10 @@ module.exports = class Network {
22
22
  if (settings.serviceUrl) {
23
23
  settings.baseURL = settings.serviceUrl;
24
24
  } else if (settings.serviceName) {
25
- settings.baseURL = process.env[`SERVICE_URL_${settings.serviceName}`];
25
+ settings.baseURL = process.env[`${settings.serviceName}_SERVICE_HOST`];
26
26
 
27
27
  if (!settings.baseURL) {
28
- throw new Error(`Missing enviermint varible: SERVICE_URL_${settings.serviceName}`);
28
+ throw new Error(`Missing enviermint varible: ${settings.serviceName}_SERVICE_HOST`);
29
29
  }
30
30
  }
31
31
 
@@ -41,4 +41,4 @@ module.exports = class Network {
41
41
  console.log('Response:', response.data)
42
42
  }));
43
43
  }
44
- }
44
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@autofleet/node-common",
3
- "version": "1.0.1",
3
+ "version": "1.0.2",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {