scharff 1.0.0
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 +19 -0
- package/constants/functions.js +10 -0
- package/index.js +53 -0
- package/package.json +18 -0
package/README.md
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# Scharff Logger
|
|
2
|
+
This project was created by Michael Scharff for logging purposes.
|
|
3
|
+
The project is using the fetch-intercept NPM package.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
1) run `npm install scharff`.
|
|
7
|
+
2) fork the git repository `https://github.com/Minka1902/scharff.git`, and place it next to your project.
|
|
8
|
+
|
|
9
|
+
## Usage
|
|
10
|
+
1) in your entry point, import unregister from the package: `const { unregister } = require('../../scharff/index');`
|
|
11
|
+
2) to stop the logger just run the unregister function: `unregister()`
|
|
12
|
+
|
|
13
|
+
## What to expect
|
|
14
|
+
The package will create a outgoingRequest.log file and start logging the requests to the file.
|
|
15
|
+
|
|
16
|
+
## Future additions
|
|
17
|
+
1) We will add a request error logger.
|
|
18
|
+
2) We will add a response logger.
|
|
19
|
+
3) We will add a response error logger.
|
package/index.js
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
const fetchIntercept = require('fetch-intercept');
|
|
2
|
+
const fs = require('fs');
|
|
3
|
+
const { removeBaseUrl } = require('./constants/functions');
|
|
4
|
+
|
|
5
|
+
module.exports.unregister = fetchIntercept.register({
|
|
6
|
+
request: function (url, config) {
|
|
7
|
+
let tempUrl = url;
|
|
8
|
+
tempUrl = removeBaseUrl(tempUrl);
|
|
9
|
+
let tempReq = { url };
|
|
10
|
+
if (tempUrl !== url) {
|
|
11
|
+
tempReq.originUrl = tempUrl;
|
|
12
|
+
}
|
|
13
|
+
if (config === undefined) {
|
|
14
|
+
tempReq.method = 'GET';
|
|
15
|
+
} else {
|
|
16
|
+
if (config) {
|
|
17
|
+
if (config.method) {
|
|
18
|
+
tempReq.method = config.method;
|
|
19
|
+
}
|
|
20
|
+
if (config.headers) {
|
|
21
|
+
tempReq.headers = config.headers;
|
|
22
|
+
}
|
|
23
|
+
if (config.body) {
|
|
24
|
+
tempReq.body = JSON.parse(config.body);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
fs.open('./outgoingRequest.log', 'a', function (e, id) {
|
|
30
|
+
fs.write(id, JSON.stringify(tempReq) + "\n", null, 'utf8', function () {
|
|
31
|
+
fs.close(id, function () {
|
|
32
|
+
});
|
|
33
|
+
});
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
return [url, config];
|
|
37
|
+
},
|
|
38
|
+
|
|
39
|
+
// requestError: function (error) {
|
|
40
|
+
// // Called when an error occurred during another 'request' interceptor call
|
|
41
|
+
// return Promise.reject(error);
|
|
42
|
+
// },
|
|
43
|
+
|
|
44
|
+
// response: function (response) {
|
|
45
|
+
// // Modify the response object
|
|
46
|
+
// return response;
|
|
47
|
+
// },
|
|
48
|
+
|
|
49
|
+
// responseError: function (error) {
|
|
50
|
+
// // Handle an fetch error
|
|
51
|
+
// return Promise.reject(error);
|
|
52
|
+
// }
|
|
53
|
+
});
|
package/package.json
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "scharff",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Logger for outgoing requests",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
8
|
+
},
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "https://github.com/Minka1902/scharff.git"
|
|
12
|
+
},
|
|
13
|
+
"author": "Michael Scharff",
|
|
14
|
+
"license": "ISC",
|
|
15
|
+
"dependencies": {
|
|
16
|
+
"fetch-intercept": "^2.4.0"
|
|
17
|
+
}
|
|
18
|
+
}
|