pingoni 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/index.js +45 -0
- package/package.json +9 -0
package/index.js
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
const https = require("https");
|
|
2
|
+
|
|
3
|
+
function pingoni(apiKey) {
|
|
4
|
+
if (!apiKey) {
|
|
5
|
+
console.warn("[Pingoni] No API key provided. Monitoring disabled.");
|
|
6
|
+
return (req, res, next) => next();
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
return (req, res, next) => {
|
|
10
|
+
const start = Date.now();
|
|
11
|
+
|
|
12
|
+
res.on("finish", () => {
|
|
13
|
+
const duration = Date.now() - start;
|
|
14
|
+
|
|
15
|
+
const data = JSON.stringify({
|
|
16
|
+
method: req.method,
|
|
17
|
+
endpoint: req.originalUrl,
|
|
18
|
+
status_code: res.statusCode,
|
|
19
|
+
response_time: duration,
|
|
20
|
+
error_message: null,
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
const options = {
|
|
24
|
+
hostname: "apiwatch-production-3f19.up.railway.app",
|
|
25
|
+
port: 443,
|
|
26
|
+
path: "/ingest",
|
|
27
|
+
method: "POST",
|
|
28
|
+
headers: {
|
|
29
|
+
"Content-Type": "application/json",
|
|
30
|
+
"Content-Length": Buffer.byteLength(data),
|
|
31
|
+
"x-api-key": apiKey,
|
|
32
|
+
},
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
const req2 = https.request(options, () => {});
|
|
36
|
+
req2.on("error", () => {});
|
|
37
|
+
req2.write(data);
|
|
38
|
+
req2.end();
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
next();
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
module.exports = pingoni;
|
package/package.json
ADDED