com.jimuwd.xian.registry-proxy 1.0.52 → 1.0.54
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 +10 -3
- package/package.json +6 -6
- package/src/index.ts +10 -3
package/dist/index.js
CHANGED
|
@@ -144,7 +144,7 @@ async function fetchFromRegistry(registry, targetUrl, limiter) {
|
|
|
144
144
|
const headers = registry.token ? { Authorization: `Bearer ${registry.token}` } : {};
|
|
145
145
|
headers.Collection = "keep-alive";
|
|
146
146
|
const response = await fetch(targetUrl, { headers });
|
|
147
|
-
console.log(`Response from upstream ${targetUrl}: ${response.status} ${response.statusText}
|
|
147
|
+
console.log(`Response from upstream ${targetUrl}: ${response.status} ${response.statusText} content-type=${response.headers.get('content-type')} content-length=${response.headers.get('content-length')} transfer-encoding=${response.headers.get('transfer-encoding')}`);
|
|
148
148
|
return response.ok ? response : null;
|
|
149
149
|
}
|
|
150
150
|
catch (e) {
|
|
@@ -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.54",
|
|
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
|
@@ -196,7 +196,7 @@ async function fetchFromRegistry(
|
|
|
196
196
|
const headers: {} = registry.token ? {Authorization: `Bearer ${registry.token}`} : {};
|
|
197
197
|
(headers as any).Collection = "keep-alive";
|
|
198
198
|
const response = await fetch(targetUrl, {headers});
|
|
199
|
-
console.log(`Response from upstream ${targetUrl}: ${response.status} ${response.statusText}
|
|
199
|
+
console.log(`Response from upstream ${targetUrl}: ${response.status} ${response.statusText} content-type=${response.headers.get('content-type')} content-length=${response.headers.get('content-length')} transfer-encoding=${response.headers.get('transfer-encoding')}`);
|
|
200
200
|
return response.ok ? response : null;
|
|
201
201
|
} catch (e) {
|
|
202
202
|
if (e instanceof Error) {
|
|
@@ -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) {
|