com.jimuwd.xian.registry-proxy 1.1.1 → 1.1.3
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/server/index.js +14 -8
- package/package.json +1 -1
package/dist/server/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import http, { createServer } from 'node:http';
|
|
3
3
|
import https, { createServer as createHttpsServer } from 'node:https';
|
|
4
|
-
import { promises as fsPromises, readFileSync } from 'node:fs';
|
|
4
|
+
import { existsSync, promises as fsPromises, readFileSync } from 'node:fs';
|
|
5
5
|
import { load } from 'js-yaml';
|
|
6
6
|
import fetch from 'node-fetch';
|
|
7
7
|
import { homedir } from 'os';
|
|
@@ -86,8 +86,14 @@ async function readProxyConfig(proxyConfigPath = './.registry-proxy.yml') {
|
|
|
86
86
|
*/
|
|
87
87
|
async function readYarnConfig(path) {
|
|
88
88
|
try {
|
|
89
|
-
|
|
90
|
-
|
|
89
|
+
if (existsSync(path)) {
|
|
90
|
+
const content = await readFile(resolvePath(path), 'utf8');
|
|
91
|
+
return load(content);
|
|
92
|
+
}
|
|
93
|
+
else {
|
|
94
|
+
logger.info(`Skip reading ${path}, because it does not exist.`);
|
|
95
|
+
return {};
|
|
96
|
+
}
|
|
91
97
|
}
|
|
92
98
|
catch (e) {
|
|
93
99
|
logger.warn(`Failed to load Yarn config from ${path}:`, e);
|
|
@@ -396,16 +402,16 @@ export async function startProxyServer(proxyConfigPath, localYarnConfigPath, glo
|
|
|
396
402
|
const promisedServer = new Promise((resolve, reject) => {
|
|
397
403
|
const errHandler = async (err) => {
|
|
398
404
|
if (err.code === 'EADDRINUSE') {
|
|
399
|
-
|
|
400
|
-
|
|
405
|
+
reject(new Error(`Port ${port} is in use, please specify a different port or free it.`, { cause: err, }));
|
|
406
|
+
}
|
|
407
|
+
else {
|
|
408
|
+
reject(new Error('Server error', { cause: err, }));
|
|
401
409
|
}
|
|
402
|
-
logger.error('Server error:', err);
|
|
403
|
-
reject(err);
|
|
404
410
|
};
|
|
405
411
|
const connectionHandler = (socket) => {
|
|
406
|
-
logger.info("Server on connection");
|
|
407
412
|
socket.setTimeout(60000);
|
|
408
413
|
socket.setKeepAlive(true, 30000);
|
|
414
|
+
logger.debug(() => "Server on connection");
|
|
409
415
|
};
|
|
410
416
|
server.on('error', errHandler /*this handler will call 'reject'*/);
|
|
411
417
|
server.on('connection', connectionHandler);
|