@autofleet/node-common 1.0.4 → 1.0.6
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 +3 -3
- package/logger/index.js +31 -0
- package/logger/test.js +4 -0
- package/network/index.js +2 -2
- package/package.json +3 -2
package/README.md
CHANGED
|
@@ -19,7 +19,7 @@ Implement:
|
|
|
19
19
|
|
|
20
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
21
|
|
|
22
|
-
In case `serviceName` used the constractor will look for an environment varible with the the name
|
|
22
|
+
In case `serviceName` used the constractor will look for an environment varible with the the name `<SERVICE_NAME>_SERVICE_HOST`.
|
|
23
23
|
|
|
24
24
|
For Example:
|
|
25
25
|
```
|
|
@@ -31,7 +31,7 @@ n.get('/posts/1');
|
|
|
31
31
|
```
|
|
32
32
|
.env file:
|
|
33
33
|
```
|
|
34
|
-
|
|
34
|
+
RIDE_SERVICE_HOST=jsonplaceholder.typicode.com
|
|
35
35
|
```
|
|
36
36
|
|
|
37
|
-
To learn more [click here](https://blog.risingstack.com/designing-microservices-architecture-for-failure/).
|
|
37
|
+
To learn more [click here](https://blog.risingstack.com/designing-microservices-architecture-for-failure/).
|
package/logger/index.js
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
const winston = require('winston')
|
|
2
|
+
|
|
3
|
+
const createLogger = (logLevel) => {
|
|
4
|
+
let level = logLevel ? logLevel : 'info'
|
|
5
|
+
const logger = winston.createLogger({
|
|
6
|
+
level,
|
|
7
|
+
format: winston.format.simple(),
|
|
8
|
+
transports: [
|
|
9
|
+
//
|
|
10
|
+
// - Write to all logs with level `info` and below to `combined.log`
|
|
11
|
+
// - Write all logs error (and below) to `error.log`.
|
|
12
|
+
//
|
|
13
|
+
new winston.transports.File({ filename: 'logs/error.log', level: 'error' }),
|
|
14
|
+
new winston.transports.File({ filename: 'logs/combined.log' })
|
|
15
|
+
]
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
//
|
|
19
|
+
// If we're not in production then log to the `console` with the format:
|
|
20
|
+
// `${info.level}: ${info.message} JSON.stringify({ ...rest }) `
|
|
21
|
+
//
|
|
22
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
23
|
+
logger.add(new winston.transports.Console({
|
|
24
|
+
format: winston.format.simple()
|
|
25
|
+
}));
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
return logger
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
module.exports = createLogger
|
package/logger/test.js
ADDED
package/network/index.js
CHANGED
|
@@ -8,7 +8,7 @@ if (process.env.NODE_ENV === 'test') {
|
|
|
8
8
|
axios.defaults.adapter = require('axios/lib/adapters/http')
|
|
9
9
|
}
|
|
10
10
|
|
|
11
|
-
const
|
|
11
|
+
const HTTPMethods = [
|
|
12
12
|
'get',
|
|
13
13
|
'post',
|
|
14
14
|
'delete',
|
|
@@ -55,6 +55,6 @@ module.exports = class Network {
|
|
|
55
55
|
*/
|
|
56
56
|
buildClassHttpMethods() {
|
|
57
57
|
this.axios = axios.create(this.settings);
|
|
58
|
-
|
|
58
|
+
HTTPMethods.map((method) => this[method] = (...args) => this.axios[method](...args))
|
|
59
59
|
}
|
|
60
60
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@autofleet/node-common",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.6",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -17,6 +17,7 @@
|
|
|
17
17
|
},
|
|
18
18
|
"homepage": "https://gitlab.com/AutoFleet/node-common#README",
|
|
19
19
|
"dependencies": {
|
|
20
|
-
"axios": "^0.18.0"
|
|
20
|
+
"axios": "^0.18.0",
|
|
21
|
+
"winston": "^3.0.0-rc5"
|
|
21
22
|
}
|
|
22
23
|
}
|