com.jimuwd.xian.registry-proxy 1.0.37 → 1.0.39
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 +6 -3
- package/package.json +1 -1
- package/src/index.ts +6 -3
package/dist/index.js
CHANGED
|
@@ -165,7 +165,9 @@ async function writeSuccessfulResponse(registryInfo, targetUrl, res, response, r
|
|
|
165
165
|
if (!response.ok)
|
|
166
166
|
throw new Error("Only 2xx response is supported");
|
|
167
167
|
try {
|
|
168
|
-
const
|
|
168
|
+
const upstreamContentType = response.headers.get('Content-Type');
|
|
169
|
+
console.log("Upstream Content-Type", upstreamContentType);
|
|
170
|
+
const contentType = upstreamContentType || 'application/octet-stream';
|
|
169
171
|
// 准备通用头信息
|
|
170
172
|
const safeHeaders = {
|
|
171
173
|
'content-type': contentType,
|
|
@@ -192,7 +194,8 @@ async function writeSuccessfulResponse(registryInfo, targetUrl, res, response, r
|
|
|
192
194
|
const tarball = data.versions[version]?.dist?.tarball;
|
|
193
195
|
if (tarball) {
|
|
194
196
|
const path = removeRegistryPrefix(tarball, registryInfos);
|
|
195
|
-
|
|
197
|
+
const proxiedTarballUrl = `${baseUrl}${path}${new URL(tarball).search || ''}`;
|
|
198
|
+
data.versions[version].dist.tarball = proxiedTarballUrl;
|
|
196
199
|
}
|
|
197
200
|
}
|
|
198
201
|
}
|
|
@@ -316,7 +319,7 @@ export async function startProxyServer(proxyConfigPath, localYarnConfigPath, glo
|
|
|
316
319
|
proxyPort = address.port;
|
|
317
320
|
const portFile = join(process.env.PROJECT_ROOT || process.cwd(), '.registry-proxy-port');
|
|
318
321
|
writeFile(portFile, proxyPort.toString()).catch(e => console.error('Failed to write port file:', e));
|
|
319
|
-
console.log(`Proxy server running on ${proxyInfo.https ? 'https' : 'http'}://localhost:${proxyPort}${basePathPrefixedWithSlash}`);
|
|
322
|
+
console.log(`Proxy server running on ${proxyInfo.https ? 'https' : 'http'}://localhost:${proxyPort}${basePathPrefixedWithSlash === '/' ? '' : basePathPrefixedWithSlash}`);
|
|
320
323
|
resolve(server);
|
|
321
324
|
});
|
|
322
325
|
});
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -228,7 +228,9 @@ async function writeSuccessfulResponse(
|
|
|
228
228
|
if (!response.ok) throw new Error("Only 2xx response is supported");
|
|
229
229
|
|
|
230
230
|
try {
|
|
231
|
-
const
|
|
231
|
+
const upstreamContentType = response.headers.get('Content-Type');
|
|
232
|
+
console.log("Upstream Content-Type", upstreamContentType);
|
|
233
|
+
const contentType = upstreamContentType || 'application/octet-stream';
|
|
232
234
|
|
|
233
235
|
// 准备通用头信息
|
|
234
236
|
const safeHeaders: OutgoingHttpHeaders = {
|
|
@@ -261,7 +263,8 @@ async function writeSuccessfulResponse(
|
|
|
261
263
|
const tarball = data.versions[version]?.dist?.tarball;
|
|
262
264
|
if (tarball) {
|
|
263
265
|
const path = removeRegistryPrefix(tarball, registryInfos);
|
|
264
|
-
|
|
266
|
+
const proxiedTarballUrl: string = `${baseUrl}${path}${new URL(tarball).search || ''}`;
|
|
267
|
+
data.versions[version]!.dist!.tarball = proxiedTarballUrl as string;
|
|
265
268
|
}
|
|
266
269
|
}
|
|
267
270
|
}
|
|
@@ -394,7 +397,7 @@ export async function startProxyServer(
|
|
|
394
397
|
proxyPort = address.port;
|
|
395
398
|
const portFile = join(process.env.PROJECT_ROOT || process.cwd(), '.registry-proxy-port');
|
|
396
399
|
writeFile(portFile, proxyPort.toString()).catch(e => console.error('Failed to write port file:', e));
|
|
397
|
-
console.log(`Proxy server running on ${proxyInfo.https ? 'https' : 'http'}://localhost:${proxyPort}${basePathPrefixedWithSlash}`);
|
|
400
|
+
console.log(`Proxy server running on ${proxyInfo.https ? 'https' : 'http'}://localhost:${proxyPort}${basePathPrefixedWithSlash === '/' ? '' : basePathPrefixedWithSlash}`);
|
|
398
401
|
resolve(server);
|
|
399
402
|
});
|
|
400
403
|
});
|