whistle.pastekitlab 1.7.6 → 1.7.7
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 +26 -8
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -162,14 +162,23 @@ async function forwardRequest(req, res, url) {
|
|
|
162
162
|
|
|
163
163
|
// 转换响应数据
|
|
164
164
|
let responseBody;
|
|
165
|
-
if (
|
|
165
|
+
if (Buffer.isBuffer(response.data)) {
|
|
166
166
|
responseBody = response.data;
|
|
167
|
-
} else if (
|
|
167
|
+
} else if (typeof response.data === 'string') {
|
|
168
168
|
responseBody = response.data;
|
|
169
169
|
} else if (typeof response.data === 'object') {
|
|
170
|
-
|
|
170
|
+
try {
|
|
171
|
+
responseBody = JSON.stringify(response.data);
|
|
172
|
+
} catch (e) {
|
|
173
|
+
responseBody = String(response.data);
|
|
174
|
+
}
|
|
171
175
|
} else {
|
|
172
|
-
responseBody = String(response.data);
|
|
176
|
+
responseBody = String(response.data || '');
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
// 确保 responseBody 是有效的字符串或 Buffer
|
|
180
|
+
if (typeof responseBody !== 'string' && !Buffer.isBuffer(responseBody)) {
|
|
181
|
+
responseBody = String(responseBody || '');
|
|
173
182
|
}
|
|
174
183
|
|
|
175
184
|
res.end(responseBody);
|
|
@@ -239,14 +248,23 @@ module.exports = (server, options) => {
|
|
|
239
248
|
|
|
240
249
|
// 转换响应数据为 Buffer 或字符串
|
|
241
250
|
let responseBody;
|
|
242
|
-
if (
|
|
251
|
+
if (Buffer.isBuffer(response.data)) {
|
|
243
252
|
responseBody = response.data;
|
|
244
|
-
} else if (
|
|
253
|
+
} else if (typeof response.data === 'string') {
|
|
245
254
|
responseBody = response.data;
|
|
246
255
|
} else if (typeof response.data === 'object') {
|
|
247
|
-
|
|
256
|
+
try {
|
|
257
|
+
responseBody = JSON.stringify(response.data);
|
|
258
|
+
} catch (e) {
|
|
259
|
+
responseBody = String(response.data);
|
|
260
|
+
}
|
|
248
261
|
} else {
|
|
249
|
-
responseBody = String(response.data);
|
|
262
|
+
responseBody = String(response.data || '');
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
// 确保 responseBody 是有效的字符串或 Buffer
|
|
266
|
+
if (typeof responseBody !== 'string' && !Buffer.isBuffer(responseBody)) {
|
|
267
|
+
responseBody = String(responseBody || '');
|
|
250
268
|
}
|
|
251
269
|
|
|
252
270
|
// 返回响应体
|
package/package.json
CHANGED