com.jimuwd.xian.registry-proxy 1.0.91 → 1.0.93
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 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -179,6 +179,7 @@ async function fetchFromRegistry(registry, targetUrl, reqFromDownstreamClient, l
|
|
|
179
179
|
}
|
|
180
180
|
}
|
|
181
181
|
async function writeResponseToDownstreamClient(registryInfo, targetUrl, resToDownstreamClient, upstreamResponse, reqFromDownstreamClient, proxyInfo, proxyPort, registryInfos) {
|
|
182
|
+
logger.info(`Writing upstream registry server ${registryInfo.normalizedRegistryUrl}'s 2xx ok response to downstream ${reqFromDownstreamClient.headers.from} ${reqFromDownstreamClient.headers["user-agent"]}`);
|
|
182
183
|
if (!upstreamResponse.ok)
|
|
183
184
|
throw new Error("Only 2xx upstream response is supported");
|
|
184
185
|
try {
|
|
@@ -204,8 +205,10 @@ async function writeResponseToDownstreamClient(registryInfo, targetUrl, resToDow
|
|
|
204
205
|
}
|
|
205
206
|
const bodyData = JSON.stringify(data);
|
|
206
207
|
const safeHeaders = { 'content-type': contentType, 'content-length': Buffer.byteLength(bodyData) };
|
|
208
|
+
// resToDownstreamClient.removeHeader('Transfer-Encoding');
|
|
209
|
+
// resToDownstreamClient.setHeader('content-type','application/json');
|
|
207
210
|
logger.info(`Response to downstream client headers`, JSON.stringify(safeHeaders), targetUrl);
|
|
208
|
-
resToDownstreamClient.writeHead(upstreamResponse.status,
|
|
211
|
+
resToDownstreamClient.writeHead(upstreamResponse.status, safeHeaders).end(bodyData);
|
|
209
212
|
}
|
|
210
213
|
else if (contentType.includes('application/octet-stream')) { // 二进制流处理
|
|
211
214
|
logger.info("Write application/octet-stream response from upstream to downstream", targetUrl);
|
|
@@ -381,6 +384,11 @@ export async function startProxyServer(proxyConfigPath, localYarnConfigPath, glo
|
|
|
381
384
|
return promisedServer;
|
|
382
385
|
}
|
|
383
386
|
if (import.meta.url === `file://${process.argv[1]}`) {
|
|
387
|
+
// 确保进程捕获异常
|
|
388
|
+
process.on('uncaughtException', (err) => {
|
|
389
|
+
logger.error('Fatal error:', err);
|
|
390
|
+
process.exit(1);
|
|
391
|
+
});
|
|
384
392
|
const [, , configPath, localYarnPath, globalYarnPath, port] = process.argv;
|
|
385
393
|
startProxyServer(configPath, localYarnPath, globalYarnPath, parseInt(port, 10) || 0).catch(err => {
|
|
386
394
|
logger.error('Failed to start server:', err);
|