com.jimuwd.xian.registry-proxy 1.1.8 → 1.1.10
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/README.MD
CHANGED
|
@@ -63,7 +63,7 @@ registries:
|
|
|
63
63
|
|
|
64
64
|
```yaml
|
|
65
65
|
unsafeHttpWhitelist:
|
|
66
|
-
- "
|
|
66
|
+
- "127.0.0.1"
|
|
67
67
|
```
|
|
68
68
|
|
|
69
69
|
### 4. 安装命令
|
|
@@ -324,7 +324,7 @@ Create a `.yarnrc.yml` file in your project root to allow Yarn to use the local
|
|
|
324
324
|
|
|
325
325
|
```yaml
|
|
326
326
|
unsafeHttpWhitelist:
|
|
327
|
-
- "
|
|
327
|
+
- "127.0.0.1"
|
|
328
328
|
```
|
|
329
329
|
|
|
330
330
|
### 4. install Script
|
|
@@ -124,8 +124,8 @@ async function main() {
|
|
|
124
124
|
throw new Error(`Proxy server not listening on port ${PROXY_PORT}`);
|
|
125
125
|
}
|
|
126
126
|
// Configure yarn
|
|
127
|
-
await execa('yarn', ['config', 'set', 'npmRegistryServer', `http://
|
|
128
|
-
console.log(`Set npmRegistryServer to http://
|
|
127
|
+
await execa('yarn', ['config', 'set', 'npmRegistryServer', `http://127.0.0.1:${PROXY_PORT}`]);
|
|
128
|
+
console.log(`Set npmRegistryServer to http://127.0.0.1:${PROXY_PORT}`);
|
|
129
129
|
registerCleanup(async () => {
|
|
130
130
|
try {
|
|
131
131
|
await execa('yarn', ['config', 'unset', 'npmRegistryServer']);
|
package/dist/server/index.js
CHANGED
|
@@ -204,7 +204,7 @@ async function writeResponseToDownstreamClient(registryInfo, targetUrl, resToDow
|
|
|
204
204
|
const data = await upstreamResponse.json();
|
|
205
205
|
if (data.versions) { // 处理node依赖包元数据
|
|
206
206
|
logger.debug(() => "Write package meta data application/json response from upstream to downstream", targetUrl);
|
|
207
|
-
const host = reqFromDownstreamClient.headers.host
|
|
207
|
+
const host = reqFromDownstreamClient.headers.host;
|
|
208
208
|
const baseUrl = `${proxyInfo.https ? 'https' : 'http'}://${host}${proxyInfo.basePath === '/' ? '' : proxyInfo.basePath}`;
|
|
209
209
|
for (const versionKey in data.versions) {
|
|
210
210
|
const packageVersion = data.versions[versionKey];
|
|
@@ -425,15 +425,17 @@ export async function startProxyServer(proxyConfigPath, localYarnConfigPath, glo
|
|
|
425
425
|
};
|
|
426
426
|
server.on('error', errHandler /*this handler will call 'reject'*/);
|
|
427
427
|
server.on('connection', connectionHandler);
|
|
428
|
-
//
|
|
429
|
-
//
|
|
430
|
-
|
|
431
|
-
|
|
428
|
+
// 安全提示:为了代理服务器的安全性,暂时只监听本机ipv6地址【127.0.0.1】,不能对本机之外暴露本代理服务地址避免造成安全隐患。
|
|
429
|
+
// 兼容性说明:
|
|
430
|
+
// 1、不使用ipv6地址因为旧的docker容器内部并未开放ipv6,为了最大成都兼容容器内运行registry-proxy,只使用ipv4了。
|
|
431
|
+
// 2、yarn客户端应当通过127.0.0.1:<port>而非localhost:<port>来访问本服务,原因是yarn客户端环境解析“localhost”至多个地址,它会尝试轮询每个地址,其中某地址可能会报错ECONNREFUSED错误码,会导致yarn install执行失败。
|
|
432
|
+
const ipv4LocalhostIp = '127.0.0.1';
|
|
433
|
+
const listenOptions = { port, host: ipv4LocalhostIp, ipv6Only: false };
|
|
432
434
|
server.listen(listenOptions, async () => {
|
|
433
435
|
const addressInfo = server.address();
|
|
434
436
|
port = addressInfo.port; // 回写上层局部变量
|
|
435
437
|
await writePortFile(port);
|
|
436
|
-
logger.info(`Proxy server running on ${proxyInfo.https ? 'https' : 'http'}
|
|
438
|
+
logger.info(`Proxy server running on ${proxyInfo.https ? 'https' : 'http'}://${ipv4LocalhostIp}:${port}${basePathPrefixedWithSlash === '/' ? '' : basePathPrefixedWithSlash}`);
|
|
437
439
|
resolve(server);
|
|
438
440
|
});
|
|
439
441
|
});
|
|
@@ -444,7 +446,7 @@ if (import.meta.url === `file://${process.argv[1]}`) {
|
|
|
444
446
|
registerProcessShutdownHook();
|
|
445
447
|
const [, , configPath, localYarnPath, globalYarnPath, port] = process.argv;
|
|
446
448
|
startProxyServer(configPath, localYarnPath, globalYarnPath, parseInt(port, 10) || 0).catch(async (err) => {
|
|
447
|
-
logger.error('Failed to start server
|
|
449
|
+
logger.error('Failed to start server', err);
|
|
448
450
|
await gracefulShutdown();
|
|
449
451
|
});
|
|
450
452
|
}
|
|
@@ -2,7 +2,7 @@ export declare function isPortFree(port: number): Promise<boolean>;
|
|
|
2
2
|
/**
|
|
3
3
|
* 检查指定端口是否可连接(有服务正在监听)
|
|
4
4
|
* @param port 要检查的端口号
|
|
5
|
-
* @param host 目标主机(默认本地
|
|
5
|
+
* @param host 目标主机(默认本地IPv4 127.0.0.1)
|
|
6
6
|
* @param timeout 超时时间(毫秒,默认1000ms)
|
|
7
7
|
*/
|
|
8
8
|
export declare function isPortConnectable(port: number, host?: string, timeout?: number): Promise<boolean>;
|
package/dist/utils/portTester.js
CHANGED
|
@@ -12,10 +12,10 @@ export async function isPortFree(port) {
|
|
|
12
12
|
/**
|
|
13
13
|
* 检查指定端口是否可连接(有服务正在监听)
|
|
14
14
|
* @param port 要检查的端口号
|
|
15
|
-
* @param host 目标主机(默认本地
|
|
15
|
+
* @param host 目标主机(默认本地IPv4 127.0.0.1)
|
|
16
16
|
* @param timeout 超时时间(毫秒,默认1000ms)
|
|
17
17
|
*/
|
|
18
|
-
export async function isPortConnectable(port, host = '
|
|
18
|
+
export async function isPortConnectable(port, host = '127.0.0.1', timeout = 1000) {
|
|
19
19
|
return new Promise((resolve) => {
|
|
20
20
|
const socket = new net.Socket();
|
|
21
21
|
// 设置超时
|
|
@@ -46,7 +46,7 @@ async function checkPortListening(port) {
|
|
|
46
46
|
socket.destroy();
|
|
47
47
|
resolve(true);
|
|
48
48
|
});
|
|
49
|
-
socket.connect({ port, host: '
|
|
49
|
+
socket.connect({ port, host: '127.0.0.1' });
|
|
50
50
|
});
|
|
51
51
|
}
|
|
52
52
|
export default { isPortFree, isPortConnectable, checkPortListening };
|