com.jimuwd.xian.registry-proxy 1.0.52 → 1.0.53
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/dist/index.js +9 -2
- package/package.json +6 -6
- package/src/index.ts +9 -2
package/dist/index.js
CHANGED
|
@@ -170,7 +170,6 @@ async function writeSuccessfulResponse(registryInfo, targetUrl, res, upstreamRes
|
|
|
170
170
|
const safeHeaders = { 'connection': connection, 'content-type': contentType, };
|
|
171
171
|
// 复制所有可能需要的头信息
|
|
172
172
|
const headersToCopy = [
|
|
173
|
-
// 'etag', 'last-modified', 'cache-control',
|
|
174
173
|
'content-length',
|
|
175
174
|
'content-encoding',
|
|
176
175
|
'transfer-encoding',
|
|
@@ -205,8 +204,16 @@ async function writeSuccessfulResponse(registryInfo, targetUrl, res, upstreamRes
|
|
|
205
204
|
res.writeHead(502).end('Empty Upstream Response');
|
|
206
205
|
}
|
|
207
206
|
else {
|
|
207
|
+
// write back to client
|
|
208
208
|
res.writeHead(upstreamResponse.status, safeHeaders);
|
|
209
|
-
|
|
209
|
+
// stop transfer if client is closed accidentally.
|
|
210
|
+
// req.on('close', () => upstreamResponse.body?.unpipe());
|
|
211
|
+
// write back body data (chunked probably)
|
|
212
|
+
upstreamResponse.body
|
|
213
|
+
.on('data', (chunk) => res.write(chunk))
|
|
214
|
+
.on('end', () => res.end())
|
|
215
|
+
.on('close', () => res.destroy(new Error(`Upstream server ${registryInfo.normalizedRegistryUrl} closed connection while transferring data on url ${targetUrl}`)))
|
|
216
|
+
.on('error', (err) => res.destroy(new Error(`Stream error: ${err.message}`, { cause: err, })));
|
|
210
217
|
}
|
|
211
218
|
}
|
|
212
219
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "com.jimuwd.xian.registry-proxy",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.53",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "A lightweight npm registry proxy with fallback support",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -12,13 +12,13 @@
|
|
|
12
12
|
"deploy": "yarn build && yarn npm publish"
|
|
13
13
|
},
|
|
14
14
|
"dependencies": {
|
|
15
|
-
"js-yaml": "
|
|
16
|
-
"node-fetch": "
|
|
15
|
+
"js-yaml": "4.1.0",
|
|
16
|
+
"node-fetch": "3.3.2"
|
|
17
17
|
},
|
|
18
18
|
"devDependencies": {
|
|
19
|
-
"@types/js-yaml": "
|
|
20
|
-
"@types/node": "
|
|
21
|
-
"typescript": "
|
|
19
|
+
"@types/js-yaml": "4.0.9",
|
|
20
|
+
"@types/node": "20.17.0",
|
|
21
|
+
"typescript": "5.8.2"
|
|
22
22
|
},
|
|
23
23
|
"packageManager": "yarn@4.6.0"
|
|
24
24
|
}
|
package/src/index.ts
CHANGED
|
@@ -235,7 +235,6 @@ async function writeSuccessfulResponse(
|
|
|
235
235
|
|
|
236
236
|
// 复制所有可能需要的头信息
|
|
237
237
|
const headersToCopy = [
|
|
238
|
-
// 'etag', 'last-modified', 'cache-control',
|
|
239
238
|
'content-length',
|
|
240
239
|
'content-encoding',
|
|
241
240
|
'transfer-encoding',
|
|
@@ -270,8 +269,16 @@ async function writeSuccessfulResponse(
|
|
|
270
269
|
console.error(`Empty response body from ${targetUrl}`);
|
|
271
270
|
res.writeHead(502).end('Empty Upstream Response');
|
|
272
271
|
} else {
|
|
272
|
+
// write back to client
|
|
273
273
|
res.writeHead(upstreamResponse.status, safeHeaders);
|
|
274
|
-
|
|
274
|
+
// stop transfer if client is closed accidentally.
|
|
275
|
+
// req.on('close', () => upstreamResponse.body?.unpipe());
|
|
276
|
+
// write back body data (chunked probably)
|
|
277
|
+
upstreamResponse.body
|
|
278
|
+
.on('data', (chunk) => res.write(chunk))
|
|
279
|
+
.on('end', () => res.end())
|
|
280
|
+
.on('close', () => res.destroy(new Error(`Upstream server ${registryInfo.normalizedRegistryUrl} closed connection while transferring data on url ${targetUrl}`)))
|
|
281
|
+
.on('error', (err: Error) => res.destroy(new Error(`Stream error: ${err.message}`, {cause: err,})));
|
|
275
282
|
}
|
|
276
283
|
}
|
|
277
284
|
} catch (err) {
|