upblit-express 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 +78 -0
- package/index.js +43 -0
- package/package.json +23 -0
package/README.md
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
# upblit-express
|
|
2
|
+
|
|
3
|
+
Simple observation and monitoring setup for Express apps using **Upblit**.
|
|
4
|
+
|
|
5
|
+
Set up application observation in seconds with just two lines of code.
|
|
6
|
+
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## π Installation
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
npm install upblit-express
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
---
|
|
16
|
+
|
|
17
|
+
## π Prerequisites
|
|
18
|
+
|
|
19
|
+
1. Create an Express application at https://upblit.dev
|
|
20
|
+
2. Generate your observation token from the dashboard
|
|
21
|
+
|
|
22
|
+
---
|
|
23
|
+
|
|
24
|
+
## β‘ Quick Setup
|
|
25
|
+
|
|
26
|
+
Add the middleware to your Express app.
|
|
27
|
+
|
|
28
|
+
```js
|
|
29
|
+
const upblit = require("upblit-express");
|
|
30
|
+
|
|
31
|
+
app.use(upblit("<YOUR_TOKEN>"));
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
Thatβs it. Observation is now enabled.
|
|
35
|
+
|
|
36
|
+
---
|
|
37
|
+
|
|
38
|
+
## π§ How It Works
|
|
39
|
+
|
|
40
|
+
`upblit-express` adds monitoring and observation capabilities to your Express application using your Upblit token. Once connected, your app automatically starts sending observation data to Upblit.
|
|
41
|
+
|
|
42
|
+
---
|
|
43
|
+
|
|
44
|
+
## π§© Example
|
|
45
|
+
|
|
46
|
+
```js
|
|
47
|
+
const express = require("express");
|
|
48
|
+
const upblit = require("upblit-express");
|
|
49
|
+
|
|
50
|
+
const app = express();
|
|
51
|
+
|
|
52
|
+
app.use(upblit("<YOUR_TOKEN>"));
|
|
53
|
+
|
|
54
|
+
app.get("/", (req, res) => {
|
|
55
|
+
res.send("Hello World");
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
app.listen(3000);
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
---
|
|
62
|
+
|
|
63
|
+
## π Token
|
|
64
|
+
|
|
65
|
+
You can obtain your token from your Upblit dashboard after creating an application.
|
|
66
|
+
|
|
67
|
+
---
|
|
68
|
+
|
|
69
|
+
## π¦ Requirements
|
|
70
|
+
|
|
71
|
+
* Node.js
|
|
72
|
+
* Express
|
|
73
|
+
|
|
74
|
+
---
|
|
75
|
+
|
|
76
|
+
## π Support
|
|
77
|
+
|
|
78
|
+
For issues or feature requests, please open an issue in the repository.
|
package/index.js
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
const axios = require("axios");
|
|
2
|
+
|
|
3
|
+
let telemetry = [];
|
|
4
|
+
|
|
5
|
+
const API_URL = "http://app.upblit.dev/api/v1/logscollector";
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
setInterval(async () => {
|
|
9
|
+
if (telemetry.length === 0) return;
|
|
10
|
+
|
|
11
|
+
try {
|
|
12
|
+
await axios.post(
|
|
13
|
+
API_URL,
|
|
14
|
+
{ telemetry },
|
|
15
|
+
{
|
|
16
|
+
headers: {
|
|
17
|
+
Authorization: `Bearer ${jwtToken}`
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
);
|
|
21
|
+
telemetry = [];
|
|
22
|
+
} catch (err) {
|
|
23
|
+
console.error("Failed to send logs:", err.message);
|
|
24
|
+
}
|
|
25
|
+
}, 30000);
|
|
26
|
+
const upblit = (key) => {
|
|
27
|
+
jwtToken = key;
|
|
28
|
+
return (req, res, next) => {
|
|
29
|
+
if (req.method == "GET" && req.originalUrl == "/health") res.send({ status: "up" });
|
|
30
|
+
res.on("finish", () => {
|
|
31
|
+
let log = {
|
|
32
|
+
timestamp: Date.now(),
|
|
33
|
+
requestMethod: req.method,
|
|
34
|
+
requestURL: req.originalUrl,
|
|
35
|
+
responseStatus: res.statusCode
|
|
36
|
+
}
|
|
37
|
+
telemetry.push(log);
|
|
38
|
+
});
|
|
39
|
+
next();
|
|
40
|
+
};
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
module.exports = upblit;
|
package/package.json
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "upblit-express",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "The Upblit SDK for express framework",
|
|
5
|
+
"homepage": "https://github.com/Debashismitra01/Upblit#readme",
|
|
6
|
+
"bugs": {
|
|
7
|
+
"url": "https://github.com/Debashismitra01/Upblit/issues"
|
|
8
|
+
},
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "git+https://github.com/Debashismitra01/Upblit.git"
|
|
12
|
+
},
|
|
13
|
+
"license": "MIT",
|
|
14
|
+
"author": "Debashis Mitra",
|
|
15
|
+
"type": "commonjs",
|
|
16
|
+
"main": "index.js",
|
|
17
|
+
"scripts": {
|
|
18
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
19
|
+
},
|
|
20
|
+
"dependencies": {
|
|
21
|
+
"axios": "^1.13.5"
|
|
22
|
+
}
|
|
23
|
+
}
|