com.jimuwd.xian.registry-proxy 1.0.39 → 1.0.40

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 CHANGED
@@ -183,26 +183,28 @@ async function writeSuccessfulResponse(registryInfo, targetUrl, res, response, r
183
183
  if (value)
184
184
  safeHeaders[header] = value;
185
185
  });
186
- res.writeHead(response.status, safeHeaders);
187
186
  if (contentType.includes('application/json')) {
188
187
  // JSON 处理逻辑
189
188
  const data = await response.json();
190
189
  if (data.versions) {
191
190
  const host = req.headers.host || `localhost:${proxyPort}`;
192
191
  const baseUrl = `${proxyInfo.https ? 'https' : 'http'}://${host}${proxyInfo.basePath === '/' ? '' : proxyInfo.basePath}`;
193
- for (const version in data.versions) {
194
- const tarball = data.versions[version]?.dist?.tarball;
192
+ for (const versionKey in data.versions) {
193
+ const packageVersion = data.versions[versionKey];
194
+ const tarball = packageVersion?.dist?.tarball;
195
195
  if (tarball) {
196
196
  const path = removeRegistryPrefix(tarball, registryInfos);
197
197
  const proxiedTarballUrl = `${baseUrl}${path}${new URL(tarball).search || ''}`;
198
- data.versions[version].dist.tarball = proxiedTarballUrl;
198
+ packageVersion.dist.tarball = proxiedTarballUrl;
199
199
  }
200
200
  }
201
201
  }
202
+ res.writeHead(200, { "content-type": contentType });
202
203
  res.end(JSON.stringify(data));
203
204
  }
204
205
  else {
205
206
  // 二进制流处理
207
+ res.writeHead(response.status, safeHeaders);
206
208
  if (!response.body) {
207
209
  console.error(`Empty response body from ${targetUrl}`);
208
210
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "com.jimuwd.xian.registry-proxy",
3
- "version": "1.0.39",
3
+ "version": "1.0.40",
4
4
  "type": "module",
5
5
  "description": "A lightweight npm registry proxy with fallback support",
6
6
  "main": "dist/index.js",
package/src/index.ts CHANGED
@@ -249,9 +249,6 @@ async function writeSuccessfulResponse(
249
249
  if (value) safeHeaders[header] = value;
250
250
  });
251
251
 
252
-
253
- res.writeHead(response.status, safeHeaders);
254
-
255
252
  if (contentType.includes('application/json')) {
256
253
  // JSON 处理逻辑
257
254
  const data = await response.json() as PackageData;
@@ -259,18 +256,21 @@ async function writeSuccessfulResponse(
259
256
  const host = req.headers.host || `localhost:${proxyPort}`;
260
257
  const baseUrl = `${proxyInfo.https ? 'https' : 'http'}://${host}${proxyInfo.basePath === '/' ? '' : proxyInfo.basePath}`;
261
258
 
262
- for (const version in data.versions) {
263
- const tarball = data.versions[version]?.dist?.tarball;
259
+ for (const versionKey in data.versions) {
260
+ const packageVersion = data.versions[versionKey];
261
+ const tarball = packageVersion?.dist?.tarball;
264
262
  if (tarball) {
265
263
  const path = removeRegistryPrefix(tarball, registryInfos);
266
264
  const proxiedTarballUrl: string = `${baseUrl}${path}${new URL(tarball).search || ''}`;
267
- data.versions[version]!.dist!.tarball = proxiedTarballUrl as string;
265
+ packageVersion!.dist!.tarball = proxiedTarballUrl as string;
268
266
  }
269
267
  }
270
268
  }
269
+ res.writeHead(200, {"content-type":contentType});
271
270
  res.end(JSON.stringify(data));
272
271
  } else {
273
272
  // 二进制流处理
273
+ res.writeHead(response.status, safeHeaders);
274
274
  if (!response.body) {
275
275
  console.error(`Empty response body from ${targetUrl}`);
276
276
  } else {