com.jimuwd.xian.registry-proxy 1.0.65 → 1.0.67
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.d.ts +2 -2
- package/dist/index.js +21 -7
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { Server as HttpServer } from 'http';
|
|
3
|
-
import { Server as HttpsServer } from 'https';
|
|
2
|
+
import { Server as HttpServer } from 'node:http';
|
|
3
|
+
import { Server as HttpsServer } from 'node:https';
|
|
4
4
|
export declare function startProxyServer(proxyConfigPath?: string, localYarnConfigPath?: string, globalYarnConfigPath?: string, port?: number): Promise<HttpServer | HttpsServer>;
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { createServer } from 'http';
|
|
3
|
-
import { createServer as createHttpsServer } from 'https';
|
|
2
|
+
import http, { createServer } from 'node:http';
|
|
3
|
+
import https, { createServer as createHttpsServer } from 'node:https';
|
|
4
4
|
import { promises as fsPromises, readFileSync } from 'fs';
|
|
5
5
|
import { load } from 'js-yaml';
|
|
6
6
|
import fetch from 'node-fetch';
|
|
@@ -160,7 +160,7 @@ async function fetchFromRegistry(registry, targetUrl, limiter) {
|
|
|
160
160
|
limiter.release();
|
|
161
161
|
}
|
|
162
162
|
}
|
|
163
|
-
async function writeResponseToDownstreamClient(registryInfo, targetUrl, resToDownstreamClient, upstreamResponse,
|
|
163
|
+
async function writeResponseToDownstreamClient(registryInfo, targetUrl, resToDownstreamClient, upstreamResponse, reqFromDownstreamClient, proxyInfo, proxyPort, registryInfos) {
|
|
164
164
|
if (!upstreamResponse.ok)
|
|
165
165
|
throw new Error("Only 2xx upstream response is supported");
|
|
166
166
|
try {
|
|
@@ -183,7 +183,7 @@ async function writeResponseToDownstreamClient(registryInfo, targetUrl, resToDow
|
|
|
183
183
|
// JSON 处理逻辑
|
|
184
184
|
const data = await upstreamResponse.json();
|
|
185
185
|
if (data.versions) {
|
|
186
|
-
const host =
|
|
186
|
+
const host = reqFromDownstreamClient.headers.host || `localhost:${proxyPort}`;
|
|
187
187
|
const baseUrl = `${proxyInfo.https ? 'https' : 'http'}://${host}${proxyInfo.basePath === '/' ? '' : proxyInfo.basePath}`;
|
|
188
188
|
for (const versionKey in data.versions) {
|
|
189
189
|
const packageVersion = data.versions[versionKey];
|
|
@@ -208,11 +208,19 @@ async function writeResponseToDownstreamClient(registryInfo, targetUrl, resToDow
|
|
|
208
208
|
resToDownstreamClient.writeHead(upstreamResponse.status, safeHeaders);
|
|
209
209
|
// stop transfer if client is closed accidentally.
|
|
210
210
|
const cleanup = () => {
|
|
211
|
-
|
|
212
|
-
logger.warn(`Downstream client closed accidentally, stop pipe from upstream ${targetUrl} to downstream client.`);
|
|
211
|
+
reqFromDownstreamClient.off('close', cleanup);
|
|
212
|
+
logger.warn(`Downstream client closed connection accidentally, stop pipe from upstream ${targetUrl} to downstream client.`);
|
|
213
213
|
upstreamResponse.body?.unpipe();
|
|
214
|
+
resToDownstreamClient.destroy();
|
|
215
|
+
};
|
|
216
|
+
reqFromDownstreamClient.on('close', cleanup);
|
|
217
|
+
const cleanup0 = () => {
|
|
218
|
+
resToDownstreamClient.off('close', cleanup0);
|
|
219
|
+
logger.info(`Downstream client closed connection, destroy connection, upstream url is ${targetUrl}`);
|
|
220
|
+
upstreamResponse.body?.unpipe();
|
|
221
|
+
resToDownstreamClient.destroy();
|
|
214
222
|
};
|
|
215
|
-
|
|
223
|
+
resToDownstreamClient.on('close', cleanup0);
|
|
216
224
|
// write back body data (chunked probably)
|
|
217
225
|
// pipe upstream body to downstream client
|
|
218
226
|
upstreamResponse.body.pipe(resToDownstreamClient, { end: false });
|
|
@@ -306,10 +314,16 @@ export async function startProxyServer(proxyConfigPath, localYarnConfigPath, glo
|
|
|
306
314
|
cert: readFileSync(certPath),
|
|
307
315
|
};
|
|
308
316
|
server = createHttpsServer(httpsOptions, requestHandler);
|
|
317
|
+
logger.info("Proxy server's maxSockets is", https.globalAgent.maxSockets);
|
|
309
318
|
}
|
|
310
319
|
else {
|
|
311
320
|
server = createServer(requestHandler);
|
|
321
|
+
logger.info("Proxy server's maxSockets is", http.globalAgent.maxSockets);
|
|
312
322
|
}
|
|
323
|
+
logger.info(`Proxy server's initial maxConnections is ${server.maxConnections}, adjusting to 10000`);
|
|
324
|
+
server.maxConnections = 10000;
|
|
325
|
+
logger.info(`Proxy server's initial timeout is ${server.timeout}, adjusting to 60000ms`);
|
|
326
|
+
server.timeout = 60000;
|
|
313
327
|
const promisedServer = new Promise((resolve, reject) => {
|
|
314
328
|
server.on('error', (err) => {
|
|
315
329
|
if (err.code === 'EADDRINUSE') {
|