com.jimuwd.xian.registry-proxy 1.0.125 → 1.0.126
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 -14
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -11,7 +11,7 @@ import logger from "./utils/logger.js";
|
|
|
11
11
|
import ConcurrencyLimiter from "./utils/ConcurrencyLimiter.js";
|
|
12
12
|
import { gracefulShutdown } from "./gracefullShutdown.js";
|
|
13
13
|
import { writePortFile } from "./port.js";
|
|
14
|
-
const { readFile
|
|
14
|
+
const { readFile } = fsPromises;
|
|
15
15
|
const limiter = new ConcurrencyLimiter(Infinity);
|
|
16
16
|
function removeEndingSlashAndForceStartingSlash(str) {
|
|
17
17
|
if (!str)
|
|
@@ -165,12 +165,12 @@ async function writeResponseToDownstreamClient(registryInfo, targetUrl, resToDow
|
|
|
165
165
|
if (!upstreamResponse.ok)
|
|
166
166
|
throw new Error("Only 2xx upstream response is supported");
|
|
167
167
|
try {
|
|
168
|
-
const contentType = upstreamResponse.headers.get("content-type")
|
|
168
|
+
const contentType = upstreamResponse.headers.get("content-type");
|
|
169
169
|
if (!contentType) {
|
|
170
170
|
logger.error(`Response from upstream content-type header is absent, ${targetUrl} `);
|
|
171
|
-
|
|
171
|
+
await gracefulShutdown();
|
|
172
172
|
}
|
|
173
|
-
if (contentType.includes('application/json')) { // JSON 处理逻辑
|
|
173
|
+
else if (contentType.includes('application/json')) { // JSON 处理逻辑
|
|
174
174
|
const data = await upstreamResponse.json();
|
|
175
175
|
if (data.versions) { // 处理node依赖包元数据
|
|
176
176
|
logger.info("Write package meta data application/json response from upstream to downstream", targetUrl);
|
|
@@ -371,7 +371,7 @@ export async function startProxyServer(proxyConfigPath, localYarnConfigPath, glo
|
|
|
371
371
|
}
|
|
372
372
|
catch (e) {
|
|
373
373
|
logger.error(`HTTPS config error: key or cert file not found`, e);
|
|
374
|
-
|
|
374
|
+
await gracefulShutdown();
|
|
375
375
|
}
|
|
376
376
|
const httpsOptions = {
|
|
377
377
|
key: readFileSync(keyPath),
|
|
@@ -392,10 +392,10 @@ export async function startProxyServer(proxyConfigPath, localYarnConfigPath, glo
|
|
|
392
392
|
logger.info(`Proxy server's initial timeout is ${server.timeout}ms, adjusting to ${serverTimeoutMs}ms`);
|
|
393
393
|
server.timeout = serverTimeoutMs;
|
|
394
394
|
const promisedServer = new Promise((resolve, reject) => {
|
|
395
|
-
const errHandler = (err) => {
|
|
395
|
+
const errHandler = async (err) => {
|
|
396
396
|
if (err.code === 'EADDRINUSE') {
|
|
397
397
|
logger.error(`Port ${port} is in use, please specify a different port or free it.`, err);
|
|
398
|
-
|
|
398
|
+
await gracefulShutdown();
|
|
399
399
|
}
|
|
400
400
|
logger.error('Server error:', err);
|
|
401
401
|
reject(err);
|
|
@@ -421,14 +421,9 @@ export async function startProxyServer(proxyConfigPath, localYarnConfigPath, glo
|
|
|
421
421
|
return promisedServer;
|
|
422
422
|
}
|
|
423
423
|
if (import.meta.url === `file://${process.argv[1]}`) {
|
|
424
|
-
// 确保进程捕获异常
|
|
425
|
-
process.on('uncaughtException', (err) => {
|
|
426
|
-
logger.error('Fatal error:', err);
|
|
427
|
-
process.exit(1);
|
|
428
|
-
});
|
|
429
424
|
const [, , configPath, localYarnPath, globalYarnPath, port] = process.argv;
|
|
430
|
-
startProxyServer(configPath, localYarnPath, globalYarnPath, parseInt(port, 10) || 0).catch(err => {
|
|
425
|
+
startProxyServer(configPath, localYarnPath, globalYarnPath, parseInt(port, 10) || 0).catch(async (err) => {
|
|
431
426
|
logger.error('Failed to start server:', err);
|
|
432
|
-
|
|
427
|
+
await gracefulShutdown();
|
|
433
428
|
});
|
|
434
429
|
}
|