com.jimuwd.xian.registry-proxy 1.0.113 → 1.0.115

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.
Files changed (2) hide show
  1. package/dist/index.js +10 -9
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -308,7 +308,7 @@ export async function startProxyServer(proxyConfigPath, localYarnConfigPath, glo
308
308
  logger.info('Proxy base path:', basePathPrefixedWithSlash);
309
309
  logger.info('HTTPS:', !!proxyInfo.https);
310
310
  // the real port server is listening on if configured port is empty or 0
311
- let proxyPort;
311
+ let realPort = port;
312
312
  const requestHandler = async (reqFromDownstreamClient, resToDownstreamClient) => {
313
313
  const downstreamUserAgent = reqFromDownstreamClient.headers["user-agent"]; // "curl/x.x.x"
314
314
  const downstreamIp = getDownstreamClientIp(reqFromDownstreamClient);
@@ -354,7 +354,7 @@ export async function startProxyServer(proxyConfigPath, localYarnConfigPath, glo
354
354
  }
355
355
  // 统一回写响应
356
356
  if (successfulResponseFromUpstream) {
357
- await writeResponseToDownstreamClient(targetRegistry, targetUrl, resToDownstreamClient, successfulResponseFromUpstream, reqFromDownstreamClient, proxyInfo, proxyPort, registryInfos);
357
+ await writeResponseToDownstreamClient(targetRegistry, targetUrl, resToDownstreamClient, successfulResponseFromUpstream, reqFromDownstreamClient, proxyInfo, realPort, registryInfos);
358
358
  }
359
359
  else {
360
360
  resToDownstreamClient.writeHead(404).end('All upstream registries failed');
@@ -400,7 +400,7 @@ export async function startProxyServer(proxyConfigPath, localYarnConfigPath, glo
400
400
  const promisedServer = new Promise((resolve, reject) => {
401
401
  const errHandler = (err) => {
402
402
  if (err.code === 'EADDRINUSE') {
403
- logger.error(`Port ${port} is in use, please specify a different port or free it.`, err);
403
+ logger.error(`Port ${realPort} is in use, please specify a different port or free it.`, err);
404
404
  process.exit(1);
405
405
  }
406
406
  logger.error('Server error:', err);
@@ -417,13 +417,14 @@ export async function startProxyServer(proxyConfigPath, localYarnConfigPath, glo
417
417
  serverIpv4.on('connection', connectionHandler);
418
418
  // 为了代理服务器的健壮性,先启动ipv6监听,然后再在其回调函数中启动ipv4监听
419
419
  serverIpv6.listen(port, '::', () => {
420
- const address = serverIpv6.address();
421
- proxyPort = address.port;
422
- logger.info(`前面已经监听了ipv6端口 ${address},追加监听Ipv4同端口号 0.0.0.0:${proxyPort}`);
423
- serverIpv4.listen(proxyPort, '0.0.0.0', () => {
420
+ const addressInfo = serverIpv6.address();
421
+ // 回写上层局部变量
422
+ realPort = addressInfo.port;
423
+ logger.info(`前面已经监听了ipv6端口 ${addressInfo.address} ${addressInfo.port},追加监听Ipv4同端口号 0.0.0.0:${addressInfo.port}`);
424
+ serverIpv4.listen(addressInfo.port, '0.0.0.0', () => {
424
425
  const portFile = join(process.env.PROJECT_ROOT || process.cwd(), '.registry-proxy-port');
425
- writeFile(portFile, proxyPort.toString()).catch(e => logger.error(`Failed to write port file: ${portFile}`, e));
426
- logger.info(`Proxy server running on ${proxyInfo.https ? 'https' : 'http'}://localhost:${proxyPort}${basePathPrefixedWithSlash === '/' ? '' : basePathPrefixedWithSlash}`);
426
+ writeFile(portFile, addressInfo.port.toString()).catch(e => logger.error(`Failed to write port file: ${portFile}`, e));
427
+ logger.info(`Proxy server running on ${proxyInfo.https ? 'https' : 'http'}://localhost:${addressInfo.port}${basePathPrefixedWithSlash === '/' ? '' : basePathPrefixedWithSlash}`);
427
428
  resolve({ serverIpv6, serverIpv4, });
428
429
  });
429
430
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "com.jimuwd.xian.registry-proxy",
3
- "version": "1.0.113",
3
+ "version": "1.0.115",
4
4
  "description": "A lightweight npm registry proxy with fallback support",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",