whistle.pastekitlab 1.3.4 → 1.3.5

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.
Files changed (2) hide show
  1. package/index.js +48 -12
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -1,13 +1,49 @@
1
- module.exports = (server, options) => {
2
- console.log('>>> plugin loaded');
3
- // server.on('request', (req, res) => {
4
- // console.log('>>> takeover:', req.fullUrl);
5
- // // 直接用
6
- // });
7
- return {
8
- request: (req, res,next) => {
9
- console.log('>>> takeover:', req.fullUrl,next);
10
- return next();
11
- }
1
+ module.exports = (req, res, next) => {
2
+ // 📥 监听请求数据(可选)
3
+ let reqBody = '';
4
+ req.on('data', chunk => {
5
+ reqBody += chunk.toString();
6
+ });
7
+
8
+ // 📤 监听响应数据(关键!)
9
+ const originalWrite = res.write;
10
+ const originalEnd = res.end;
11
+
12
+ let resBody = '';
13
+ res.write = function(chunk, ...args) {
14
+ if (chunk) resBody += chunk.toString();
15
+ return originalWrite.apply(this, [chunk, ...args]);
12
16
  };
13
- };
17
+
18
+ res.end = function(chunk, ...args) {
19
+ if (chunk) resBody += chunk.toString();
20
+
21
+ // 🔍 在这里处理完整的请求/响应数据(只读!)
22
+ console.log('📡 URL:', req.fullUrl);
23
+ console.log('📥 Request Body:', reqBody);
24
+ console.log('📤 Response Body:', resBody);
25
+ console.log('📊 Status Code:', res.statusCode);
26
+
27
+ // ⚠️ 必须调用原始 end 并继续流程
28
+ return originalEnd.apply(this, [chunk, ...args]);
29
+ };
30
+
31
+ // ➡️ 继续 Whistle 默认代理流程
32
+ next();
33
+ };
34
+
35
+
36
+
37
+ // (server, options) => {
38
+ // console.log('>>> plugin loaded');
39
+ // // server.on('request', (req, res) => {
40
+ // // console.log('>>> takeover:', req.fullUrl);
41
+ // // // 直接用
42
+ // // });
43
+ // return {
44
+ // request: (req, res) => {
45
+ // console.log('>>> takeover:', req.fullUrl,next);
46
+ // return next();
47
+ // }
48
+ // };
49
+ // };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "whistle.pastekitlab",
3
- "version": "1.3.4",
3
+ "version": "1.3.5",
4
4
  "description": "Whistle plugin for PasteKit Lab - Intercepts requests and sends them to requestlistviewer via WebSocket",
5
5
  "main": "index.js",
6
6
  "scripts": {