com.jimuwd.xian.registry-proxy 1.0.89 → 1.0.92
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 +12 -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 {
|
|
@@ -186,6 +187,7 @@ async function writeResponseToDownstreamClient(registryInfo, targetUrl, resToDow
|
|
|
186
187
|
if (contentType.includes('application/json')) { // JSON 处理逻辑
|
|
187
188
|
const data = await upstreamResponse.json();
|
|
188
189
|
if (data.versions) { // 处理node依赖包元数据
|
|
190
|
+
logger.info("Write package meta data application/json response from upstream to downstream", targetUrl);
|
|
189
191
|
const host = reqFromDownstreamClient.headers.host || `localhost:${proxyPort}`;
|
|
190
192
|
const baseUrl = `${proxyInfo.https ? 'https' : 'http'}://${host}${proxyInfo.basePath === '/' ? '' : proxyInfo.basePath}`;
|
|
191
193
|
for (const versionKey in data.versions) {
|
|
@@ -198,12 +200,16 @@ async function writeResponseToDownstreamClient(registryInfo, targetUrl, resToDow
|
|
|
198
200
|
}
|
|
199
201
|
}
|
|
200
202
|
}
|
|
203
|
+
else {
|
|
204
|
+
logger.info("Write none meta data application/json response from upstream to downstream", targetUrl);
|
|
205
|
+
}
|
|
201
206
|
const bodyData = JSON.stringify(data);
|
|
202
207
|
const safeHeaders = { 'content-type': contentType, 'content-length': Buffer.byteLength(bodyData) };
|
|
203
208
|
logger.info(`Response to downstream client headers`, JSON.stringify(safeHeaders), targetUrl);
|
|
204
209
|
resToDownstreamClient.writeHead(upstreamResponse.status, { 'content-type': 'application/json' }).end(bodyData);
|
|
205
210
|
}
|
|
206
211
|
else if (contentType.includes('application/octet-stream')) { // 二进制流处理
|
|
212
|
+
logger.info("Write application/octet-stream response from upstream to downstream", targetUrl);
|
|
207
213
|
// 准备通用响应头信息
|
|
208
214
|
const safeHeaders = {};
|
|
209
215
|
// 复制所有可能需要的头信息(不包含安全相关的敏感头信息,如access-control-allow-origin、set-cookie、server、strict-transport-security等,这意味着代理服务器向下游客户端屏蔽了这些认证等安全数据)
|
|
@@ -261,7 +267,7 @@ async function writeResponseToDownstreamClient(registryInfo, targetUrl, resToDow
|
|
|
261
267
|
}
|
|
262
268
|
}
|
|
263
269
|
else {
|
|
264
|
-
logger.warn(`
|
|
270
|
+
logger.warn(`Write unsupported content-type=${contentType} response from upstream to downstream ${targetUrl}`);
|
|
265
271
|
const bodyData = await upstreamResponse.text();
|
|
266
272
|
const safeHeaders = { 'content-type': contentType, 'content-length': Buffer.byteLength(bodyData) };
|
|
267
273
|
logger.info(`Response to downstream client headers`, JSON.stringify(safeHeaders), targetUrl);
|
|
@@ -376,6 +382,11 @@ export async function startProxyServer(proxyConfigPath, localYarnConfigPath, glo
|
|
|
376
382
|
return promisedServer;
|
|
377
383
|
}
|
|
378
384
|
if (import.meta.url === `file://${process.argv[1]}`) {
|
|
385
|
+
// 确保进程捕获异常
|
|
386
|
+
process.on('uncaughtException', (err) => {
|
|
387
|
+
logger.error('Fatal error:', err);
|
|
388
|
+
process.exit(1);
|
|
389
|
+
});
|
|
379
390
|
const [, , configPath, localYarnPath, globalYarnPath, port] = process.argv;
|
|
380
391
|
startProxyServer(configPath, localYarnPath, globalYarnPath, parseInt(port, 10) || 0).catch(err => {
|
|
381
392
|
logger.error('Failed to start server:', err);
|