@abtnode/core 1.16.45-beta-20250614-101901-d1700f8d → 1.16.45-beta-20250620-082630-c0c76051
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/lib/api/node.js +7 -1
- package/lib/blocklet/migration-dist/migration.cjs +1 -1
- package/lib/event/index.js +24 -2
- package/lib/event/util.js +71 -0
- package/lib/index.js +1 -1
- package/lib/router/helper.js +17 -0
- package/lib/router/index.js +29 -0
- package/lib/router/manager.js +10 -5
- package/lib/util/index.js +7 -5
- package/lib/util/router.js +19 -0
- package/package.json +26 -26
package/lib/api/node.js
CHANGED
|
@@ -8,7 +8,7 @@ const isGitpod = require('@abtnode/util/lib/is-gitpod');
|
|
|
8
8
|
const getFolderSize = require('@abtnode/util/lib/get-folder-size');
|
|
9
9
|
const canPackageReadWrite = require('@abtnode/util/lib/can-pkg-rw');
|
|
10
10
|
const { toDelegateAddress } = require('@arcblock/did-util');
|
|
11
|
-
const { MONITOR_RECORD_INTERVAL_SEC } = require('@abtnode/constant');
|
|
11
|
+
const { MONITOR_RECORD_INTERVAL_SEC, NODE_MODES } = require('@abtnode/constant');
|
|
12
12
|
|
|
13
13
|
const logger = require('@abtnode/logger')('@abtnode/core:api:node');
|
|
14
14
|
|
|
@@ -74,6 +74,12 @@ class NodeAPI {
|
|
|
74
74
|
return diskInfo;
|
|
75
75
|
}
|
|
76
76
|
|
|
77
|
+
// Do not get real disk info for serverless mode to avoid too much resource usage
|
|
78
|
+
const info = await this.state.read();
|
|
79
|
+
if (info.mode === NODE_MODES.SERVERLESS) {
|
|
80
|
+
return diskInfo;
|
|
81
|
+
}
|
|
82
|
+
|
|
77
83
|
try {
|
|
78
84
|
const [app, cache, log, data, blocklets] = await Promise.all([
|
|
79
85
|
getFolderSize(this.state.dataDirs.core),
|
|
@@ -38889,7 +38889,7 @@ module.exports = require("zlib");
|
|
|
38889
38889
|
/***/ ((module) => {
|
|
38890
38890
|
|
|
38891
38891
|
"use strict";
|
|
38892
|
-
module.exports = /*#__PURE__*/JSON.parse('{"name":"@abtnode/core","publishConfig":{"access":"public"},"version":"1.16.44","description":"","main":"lib/index.js","files":["lib"],"scripts":{"lint":"eslint tests lib --ignore-pattern \'tests/assets/*\'","lint:fix":"eslint --fix tests lib","test":"node tools/jest.js","coverage":"npm run test -- --coverage"},"keywords":[],"author":"wangshijun <wangshijun2010@gmail.com> (http://github.com/wangshijun)","license":"Apache-2.0","dependencies":{"@abtnode/analytics":"1.16.44","@abtnode/auth":"1.16.44","@abtnode/certificate-manager":"1.16.44","@abtnode/client":"1.16.44","@abtnode/constant":"1.16.44","@abtnode/cron":"1.16.44","@abtnode/db-cache":"1.16.44","@abtnode/docker-utils":"1.16.44","@abtnode/logger":"1.16.44","@abtnode/models":"1.16.44","@abtnode/queue":"1.16.44","@abtnode/rbac":"1.16.44","@abtnode/router-provider":"1.16.44","@abtnode/static-server":"1.16.44","@abtnode/timemachine":"1.16.44","@abtnode/util":"1.16.44","@arcblock/did":"1.20.14","@arcblock/did-auth":"1.20.14","@arcblock/did-ext":"1.20.14","@arcblock/did-motif":"^1.1.13","@arcblock/did-util":"1.20.14","@arcblock/event-hub":"1.20.14","@arcblock/jwt":"1.20.14","@arcblock/pm2-events":"^0.0.5","@arcblock/validator":"1.20.14","@arcblock/vc":"1.20.14","@blocklet/constant":"1.16.44","@blocklet/did-space-js":"^1.0.
|
|
38892
|
+
module.exports = /*#__PURE__*/JSON.parse('{"name":"@abtnode/core","publishConfig":{"access":"public"},"version":"1.16.44","description":"","main":"lib/index.js","files":["lib"],"scripts":{"lint":"eslint tests lib --ignore-pattern \'tests/assets/*\'","lint:fix":"eslint --fix tests lib","test":"node tools/jest.js","coverage":"npm run test -- --coverage"},"keywords":[],"author":"wangshijun <wangshijun2010@gmail.com> (http://github.com/wangshijun)","license":"Apache-2.0","dependencies":{"@abtnode/analytics":"1.16.44","@abtnode/auth":"1.16.44","@abtnode/certificate-manager":"1.16.44","@abtnode/client":"1.16.44","@abtnode/constant":"1.16.44","@abtnode/cron":"1.16.44","@abtnode/db-cache":"1.16.44","@abtnode/docker-utils":"1.16.44","@abtnode/logger":"1.16.44","@abtnode/models":"1.16.44","@abtnode/queue":"1.16.44","@abtnode/rbac":"1.16.44","@abtnode/router-provider":"1.16.44","@abtnode/static-server":"1.16.44","@abtnode/timemachine":"1.16.44","@abtnode/util":"1.16.44","@arcblock/did":"1.20.14","@arcblock/did-auth":"1.20.14","@arcblock/did-ext":"1.20.14","@arcblock/did-motif":"^1.1.13","@arcblock/did-util":"1.20.14","@arcblock/event-hub":"1.20.14","@arcblock/jwt":"1.20.14","@arcblock/pm2-events":"^0.0.5","@arcblock/validator":"1.20.14","@arcblock/vc":"1.20.14","@blocklet/constant":"1.16.44","@blocklet/did-space-js":"^1.0.62","@blocklet/env":"1.16.44","@blocklet/error":"^0.2.5","@blocklet/meta":"1.16.44","@blocklet/resolver":"1.16.44","@blocklet/sdk":"1.16.44","@blocklet/store":"1.16.44","@blocklet/theme":"^2.13.70","@fidm/x509":"^1.2.1","@ocap/mcrypto":"1.20.14","@ocap/util":"1.20.14","@ocap/wallet":"1.20.14","@slack/webhook":"^5.0.4","archiver":"^7.0.1","axios":"^1.7.9","axon":"^2.0.3","chalk":"^4.1.2","cross-spawn":"^7.0.3","dayjs":"^1.11.13","deep-diff":"^1.0.2","detect-port":"^1.5.1","envfile":"^7.1.0","escape-string-regexp":"^4.0.0","fast-glob":"^3.3.2","filesize":"^10.1.1","flat":"^5.0.2","fs-extra":"^11.2.0","get-port":"^5.1.1","hasha":"^5.2.2","is-base64":"^1.1.0","is-cidr":"4","is-ip":"3","is-url":"^1.2.4","joi":"17.12.2","joi-extension-semver":"^5.0.0","js-yaml":"^4.1.0","kill-port":"^2.0.1","lodash":"^4.17.21","node-stream-zip":"^1.15.0","p-all":"^3.0.0","p-limit":"^3.1.0","p-map":"^4.0.0","p-retry":"^4.6.2","p-wait-for":"^3.2.0","rate-limiter-flexible":"^5.0.5","read-last-lines":"^1.8.0","semver":"^7.6.3","sequelize":"^6.35.0","shelljs":"^0.8.5","slugify":"^1.6.6","ssri":"^8.0.1","stream-throttle":"^0.1.3","stream-to-promise":"^3.0.0","systeminformation":"^5.23.3","tail":"^2.2.4","tar":"^6.1.11","transliteration":"^2.3.5","ua-parser-js":"^1.0.2","ufo":"^1.5.3","uuid":"^9.0.1","valid-url":"^1.0.9","which":"^2.0.2","xbytes":"^1.8.0"},"devDependencies":{"expand-tilde":"^2.0.2","express":"^4.18.2","jest":"^29.7.0","unzipper":"^0.10.11"},"gitHead":"e5764f753181ed6a7c615cd4fc6682aacf0cb7cd"}');
|
|
38893
38893
|
|
|
38894
38894
|
/***/ }),
|
|
38895
38895
|
|
package/lib/event/index.js
CHANGED
|
@@ -3,7 +3,6 @@ const { EventEmitter } = require('events');
|
|
|
3
3
|
const { wipeSensitiveData, getDisplayName } = require('@blocklet/meta/lib/util');
|
|
4
4
|
const logger = require('@abtnode/logger')('@abtnode/core:event');
|
|
5
5
|
const {
|
|
6
|
-
BLOCKLET_MODES,
|
|
7
6
|
BlockletStatus,
|
|
8
7
|
BlockletSource,
|
|
9
8
|
BlockletEvents,
|
|
@@ -35,9 +34,14 @@ const states = require('../states');
|
|
|
35
34
|
const { getBackupEndpoint, getBackupFilesUrlFromEndpoint, getDIDSpacesUrlFromEndpoint } = require('../util/spaces');
|
|
36
35
|
const { autoBackupHandlerFactory, autoBackupHandler } = require('./auto-backup-handler');
|
|
37
36
|
|
|
38
|
-
const routingSnapshotPrefix = (blocklet) => (blocklet.mode === BLOCKLET_MODES.DEVELOPMENT ? '[DEV] ' : '');
|
|
39
37
|
const eventBusHandler = require('../blocklet/webhook/event-bus');
|
|
40
38
|
const { isDevelopmentMode, deleteBlockletCache } = require('../util/blocklet');
|
|
39
|
+
const {
|
|
40
|
+
backupBlockletSites,
|
|
41
|
+
cleanBlockletSitesBackup,
|
|
42
|
+
rollbackBlockletSites,
|
|
43
|
+
routingSnapshotPrefix,
|
|
44
|
+
} = require('./util');
|
|
41
45
|
|
|
42
46
|
/**
|
|
43
47
|
*
|
|
@@ -212,7 +216,12 @@ module.exports = ({
|
|
|
212
216
|
};
|
|
213
217
|
|
|
214
218
|
const handleBlockletUpgrade = async (name, { blocklet, context }) => {
|
|
219
|
+
let sites;
|
|
220
|
+
let backupFile = null;
|
|
215
221
|
try {
|
|
222
|
+
({ sites, backupFile } = await backupBlockletSites(blocklet));
|
|
223
|
+
logger.info('sites before update blocklet routing', { event: name, did: blocklet.meta.did, sites });
|
|
224
|
+
|
|
216
225
|
const changed = await ensureBlockletRoutingForUpgrade(blocklet, context);
|
|
217
226
|
if (changed) {
|
|
218
227
|
const hash = await takeRoutingSnapshot(
|
|
@@ -223,8 +232,21 @@ module.exports = ({
|
|
|
223
232
|
}
|
|
224
233
|
|
|
225
234
|
await teamAPI.refreshBlockletInterfacePermissions(blocklet.meta);
|
|
235
|
+
|
|
236
|
+
// clean backup sites after success
|
|
237
|
+
sites = null;
|
|
238
|
+
cleanBlockletSitesBackup(backupFile);
|
|
226
239
|
} catch (error) {
|
|
227
240
|
logger.error('upgrade blocklet routing rules error', { event: name, error });
|
|
241
|
+
|
|
242
|
+
rollbackBlockletSites({ blocklet, sites, backupFile, takeRoutingSnapshot, context })
|
|
243
|
+
.then(() => {
|
|
244
|
+
logger.info('rollback blocklet routing rules success', { event: name, did: blocklet.meta.did });
|
|
245
|
+
})
|
|
246
|
+
.catch((err) => {
|
|
247
|
+
logger.error('rollback blocklet routing rules error', { event: name, error: err });
|
|
248
|
+
});
|
|
249
|
+
|
|
228
250
|
teamManager.createNotification({
|
|
229
251
|
title: 'Blocklet URL Mapping Error',
|
|
230
252
|
// eslint-disable-next-line max-len
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
const path = require('path');
|
|
2
|
+
const fs = require('fs');
|
|
3
|
+
const logger = require('@abtnode/logger')('@abtnode/core:event');
|
|
4
|
+
const { BLOCKLET_MODES } = require('@blocklet/constant');
|
|
5
|
+
|
|
6
|
+
const states = require('../states');
|
|
7
|
+
|
|
8
|
+
const routingSnapshotPrefix = (blocklet) => (blocklet.mode === BLOCKLET_MODES.DEVELOPMENT ? '[DEV] ' : '');
|
|
9
|
+
|
|
10
|
+
const backupBlockletSites = async (blocklet) => {
|
|
11
|
+
const sites = await states.site.getSitesByBlocklet(blocklet.meta.did);
|
|
12
|
+
let backupFile = null;
|
|
13
|
+
try {
|
|
14
|
+
backupFile = path.join(blocklet.env.cacheDir, `sites-backup-${Date.now()}.json`);
|
|
15
|
+
logger.info(`backup blocklet sites to ${backupFile}`, { did: blocklet.meta.did, sites });
|
|
16
|
+
fs.writeFileSync(backupFile, JSON.stringify(sites));
|
|
17
|
+
logger.info('backup blocklet sites', { did: blocklet.meta.did, backupFile });
|
|
18
|
+
} catch (error) {
|
|
19
|
+
logger.error('backup blocklet sites error', { error });
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
return { sites, backupFile };
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
const rollbackBlockletSites = async ({ blocklet, sites, backupFile, takeRoutingSnapshot, context }) => {
|
|
26
|
+
try {
|
|
27
|
+
let sitesToRestore = sites;
|
|
28
|
+
logger.info('rollback blocklet sites', { did: blocklet.meta.did, sites, backupFile });
|
|
29
|
+
if (!sitesToRestore && backupFile && fs.existsSync(backupFile)) {
|
|
30
|
+
sitesToRestore = JSON.parse(fs.readFileSync(backupFile, 'utf8'));
|
|
31
|
+
logger.info('rollback sites from backup file', { did: blocklet.meta.did, backupFile });
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
if (!sitesToRestore) {
|
|
35
|
+
logger.info('no blocklet sites to rollback', { did: blocklet.meta.did, sites, backupFile });
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const promises = sitesToRestore.map((site) => states.site.update({ id: site.id }, { $set: { rules: site.rules } }));
|
|
39
|
+
await Promise.all(promises);
|
|
40
|
+
logger.info('rollback blocklet sites rules success to database', { did: blocklet.meta.did, sites, backupFile });
|
|
41
|
+
|
|
42
|
+
const hash = await takeRoutingSnapshot(
|
|
43
|
+
{
|
|
44
|
+
message: `${routingSnapshotPrefix(blocklet)}Roll back sites rules for blocklet ${blocklet.meta.name}`,
|
|
45
|
+
dryRun: false,
|
|
46
|
+
},
|
|
47
|
+
context
|
|
48
|
+
);
|
|
49
|
+
|
|
50
|
+
logger.info('rollback blocklet sites success to snapshot', { did: blocklet.meta.did, hash });
|
|
51
|
+
} catch (error) {
|
|
52
|
+
logger.error('rollback blocklet sites error', { error, blocklet, sites, backupFile });
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
const cleanBlockletSitesBackup = (backupFile) => {
|
|
57
|
+
if (!backupFile || !fs.existsSync(backupFile)) {
|
|
58
|
+
logger.info('no backup file to clean', { backupFile });
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
fs.unlinkSync(backupFile);
|
|
63
|
+
logger.info('clean backup sites', { backupFile });
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
module.exports = {
|
|
67
|
+
routingSnapshotPrefix,
|
|
68
|
+
backupBlockletSites,
|
|
69
|
+
cleanBlockletSitesBackup,
|
|
70
|
+
rollbackBlockletSites,
|
|
71
|
+
};
|
package/lib/index.js
CHANGED
|
@@ -253,7 +253,7 @@ function ABTNode(options) {
|
|
|
253
253
|
});
|
|
254
254
|
|
|
255
255
|
// 4. init routing manager
|
|
256
|
-
const routerManager = new RouterManager({ certManager });
|
|
256
|
+
const routerManager = new RouterManager({ certManager, dataDirs });
|
|
257
257
|
const routingSnapshot = new RoutingSnapshot({
|
|
258
258
|
baseDir: dataDirs.core,
|
|
259
259
|
getRoutingData: async () => {
|
package/lib/router/helper.js
CHANGED
|
@@ -741,6 +741,7 @@ const decompressCertificates = async (source, dest) => {
|
|
|
741
741
|
|
|
742
742
|
const joinCertDownUrl = (baseUrl, name) => joinURL(baseUrl, '/certs', name);
|
|
743
743
|
|
|
744
|
+
const getDummyCertDownloadUrl = (baseUrl) => joinCertDownUrl(baseUrl, 'dummy.tar.gz');
|
|
744
745
|
const getIpEchoCertDownloadUrl = (baseUrl) => joinCertDownUrl(baseUrl, 'ip-abtnet-io.tar.gz');
|
|
745
746
|
const getDidDomainCertDownloadUrl = (baseUrl) => joinCertDownUrl(baseUrl, 'did-abtnet-io.tar.gz');
|
|
746
747
|
const getDownloadCertBaseUrl = (info) =>
|
|
@@ -853,6 +854,7 @@ module.exports = function getRouterHelpers({
|
|
|
853
854
|
const ipWildcardDomain = get(info, 'routing.ipWildcardDomain', '');
|
|
854
855
|
const didDomain = info.didDomain;
|
|
855
856
|
const certDownloadAddress = getDownloadCertBaseUrl(info);
|
|
857
|
+
|
|
856
858
|
if (!https || !certDownloadAddress) {
|
|
857
859
|
return;
|
|
858
860
|
}
|
|
@@ -877,6 +879,21 @@ module.exports = function getRouterHelpers({
|
|
|
877
879
|
};
|
|
878
880
|
|
|
879
881
|
const certBaseUrl = getDownloadCertBaseUrl(info);
|
|
882
|
+
|
|
883
|
+
if (!info.routing.enableDefaultServer && certBaseUrl) {
|
|
884
|
+
// update dummy certificate if not enable default server
|
|
885
|
+
// if update failed, it will not affect the normal certificate update
|
|
886
|
+
let dummyCertUrl;
|
|
887
|
+
try {
|
|
888
|
+
dummyCertUrl = getDummyCertDownloadUrl(certBaseUrl);
|
|
889
|
+
await ensureDomainCert('abtnode_dummy', dummyCertUrl);
|
|
890
|
+
|
|
891
|
+
logger.info('update dummy certificate success');
|
|
892
|
+
} catch (error) {
|
|
893
|
+
logger.error('update dummy certificate failed', { error, dummyCertUrl });
|
|
894
|
+
}
|
|
895
|
+
}
|
|
896
|
+
|
|
880
897
|
await Promise.all([
|
|
881
898
|
ensureDomainCert(ipWildcardDomain, getIpEchoCertDownloadUrl(certBaseUrl)),
|
|
882
899
|
ensureDomainCert(`*.${didDomain}`, getDidDomainCertDownloadUrl(certBaseUrl)),
|
package/lib/router/index.js
CHANGED
|
@@ -14,6 +14,7 @@ const {
|
|
|
14
14
|
GATEWAY_RATE_LIMIT,
|
|
15
15
|
GATEWAY_RATE_LIMIT_GLOBAL,
|
|
16
16
|
GATEWAY_RATE_LIMIT_METHODS,
|
|
17
|
+
DOMAIN_FOR_IP_SITE,
|
|
17
18
|
} = require('@abtnode/constant');
|
|
18
19
|
const { BLOCKLET_UI_INTERFACES, BLOCKLET_MODES } = require('@blocklet/constant');
|
|
19
20
|
|
|
@@ -70,10 +71,35 @@ const expandSites = (sites = []) => {
|
|
|
70
71
|
return result;
|
|
71
72
|
};
|
|
72
73
|
|
|
74
|
+
const isDefaultSite = (domain) => DOMAIN_FOR_DEFAULT_SITE === domain;
|
|
75
|
+
|
|
76
|
+
const isIpSite = (domain) => [DOMAIN_FOR_IP_SITE, DOMAIN_FOR_IP_SITE_REGEXP].includes(domain);
|
|
77
|
+
// const isIpSite = (domain) => DOMAIN_FOR_IP_SITE === domain;
|
|
78
|
+
|
|
79
|
+
const filterSites = ({ sites, enableDefaultServer, enableIpServer }) => {
|
|
80
|
+
let result = cloneDeep(sites);
|
|
81
|
+
|
|
82
|
+
if (!enableDefaultServer) {
|
|
83
|
+
result = result.filter((x) => !isDefaultSite(x.domain));
|
|
84
|
+
logger.info('disable default server');
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
if (!enableIpServer) {
|
|
88
|
+
result = result.filter((x) => !isIpSite(x.domain));
|
|
89
|
+
logger.info('disable ip site');
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
return result;
|
|
93
|
+
};
|
|
94
|
+
|
|
73
95
|
const getRoutingTable = ({ sites, nodeInfo }) => {
|
|
96
|
+
const enableDefaultServer = nodeInfo.routing.enableDefaultServer ?? false;
|
|
97
|
+
const enableIpServer = nodeInfo.routing.enableIpServer ?? false;
|
|
98
|
+
|
|
74
99
|
// eslint-disable-next-line no-use-before-define
|
|
75
100
|
let routingTable = Router.formatSites(sites);
|
|
76
101
|
routingTable = expandSites(routingTable);
|
|
102
|
+
routingTable = filterSites({ sites: routingTable, enableDefaultServer, enableIpServer });
|
|
77
103
|
|
|
78
104
|
// put ipWildcardDomain to last, to let blockletDomain match first
|
|
79
105
|
// e.g.
|
|
@@ -194,6 +220,8 @@ class Router {
|
|
|
194
220
|
wafPolicy,
|
|
195
221
|
cacheEnabled: isGatewayCacheEnabled(nodeInfo),
|
|
196
222
|
wafDisabledBlocklets,
|
|
223
|
+
enableDefaultServer: nodeInfo.routing.enableDefaultServer ?? false,
|
|
224
|
+
enableIpServer: nodeInfo.routing.enableIpServer ?? false,
|
|
197
225
|
});
|
|
198
226
|
}
|
|
199
227
|
|
|
@@ -410,5 +438,6 @@ Router.flattenSitesToRules = (sites = [], info = {}) => {
|
|
|
410
438
|
|
|
411
439
|
Router._expandSites = expandSites; // eslint-disable-line no-underscore-dangle
|
|
412
440
|
Router._getRoutingTable = getRoutingTable; // eslint-disable-line no-underscore-dangle
|
|
441
|
+
Router._filterSites = filterSites; // eslint-disable-line no-underscore-dangle
|
|
413
442
|
|
|
414
443
|
module.exports = Router;
|
package/lib/router/manager.js
CHANGED
|
@@ -6,7 +6,6 @@
|
|
|
6
6
|
*/
|
|
7
7
|
const https = require('https');
|
|
8
8
|
const path = require('path');
|
|
9
|
-
const os = require('os');
|
|
10
9
|
const dns = require('dns');
|
|
11
10
|
const fse = require('fs-extra');
|
|
12
11
|
const get = require('lodash/get');
|
|
@@ -55,7 +54,7 @@ const {
|
|
|
55
54
|
getDidFromDomainGroupName,
|
|
56
55
|
updateNFTDomainRecord,
|
|
57
56
|
revokeAndDeleteNFTDomainRecord,
|
|
58
|
-
|
|
57
|
+
getAvailableGatewayPorts,
|
|
59
58
|
} = require('../util/router');
|
|
60
59
|
const checkDNS = require('../util/check-dns.js');
|
|
61
60
|
|
|
@@ -117,8 +116,9 @@ const isMockedDidDomain = (domain) => {
|
|
|
117
116
|
};
|
|
118
117
|
|
|
119
118
|
class RouterManager extends EventEmitter {
|
|
120
|
-
constructor({ certManager }) {
|
|
119
|
+
constructor({ certManager, dataDirs }) {
|
|
121
120
|
super();
|
|
121
|
+
this.dataDirs = dataDirs;
|
|
122
122
|
this.certManager = certManager;
|
|
123
123
|
|
|
124
124
|
// HACK: do not emit any events from CLI
|
|
@@ -818,9 +818,14 @@ class RouterManager extends EventEmitter {
|
|
|
818
818
|
// get provider
|
|
819
819
|
const providerName = getProviderFromNodeInfo(info);
|
|
820
820
|
const Provider = getProvider(providerName);
|
|
821
|
-
const tmpDir = path.join(os.tmpdir(), `${providerName}-${Date.now()}`);
|
|
822
821
|
|
|
823
|
-
const
|
|
822
|
+
const tmpDir = path.join(this.dataDirs.tmp, `${providerName}-${Date.now()}`);
|
|
823
|
+
fse.ensureDirSync(tmpDir);
|
|
824
|
+
logger.info('validateRouterConfig.tmpDir', { tmpDir });
|
|
825
|
+
|
|
826
|
+
const { httpPort, httpsPort } = await getAvailableGatewayPorts();
|
|
827
|
+
logger.info('validateRouterConfig.gatewayPorts', { httpPort, httpsPort });
|
|
828
|
+
|
|
824
829
|
// disable cache to reduce nginx reload time and memory consumption
|
|
825
830
|
const provider = new Provider({
|
|
826
831
|
configDir: tmpDir,
|
package/lib/util/index.js
CHANGED
|
@@ -225,11 +225,13 @@ const getBaseUrls = async (node, ips) => {
|
|
|
225
225
|
const adminPath = normalizePathPrefix(info.routing.adminPath);
|
|
226
226
|
const tmpHttpPort = getPort(httpPort, DEFAULT_HTTP_PORT);
|
|
227
227
|
|
|
228
|
-
const httpUrls =
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
228
|
+
const httpUrls = info.routing.enableIpServer
|
|
229
|
+
? availableIps.map((ip) => {
|
|
230
|
+
return {
|
|
231
|
+
url: `http://${ip}${tmpHttpPort}${adminPath}`,
|
|
232
|
+
};
|
|
233
|
+
})
|
|
234
|
+
: [];
|
|
233
235
|
|
|
234
236
|
if (ipWildcardDomain) {
|
|
235
237
|
const site = sites.find((c) => (c.domainAliases || []).find((item) => item.value === ipWildcardDomain));
|
package/lib/util/router.js
CHANGED
|
@@ -11,6 +11,7 @@ const uniq = require('lodash/uniq');
|
|
|
11
11
|
const isUrl = require('is-url');
|
|
12
12
|
const isIp = require('is-ip');
|
|
13
13
|
const isCidr = require('is-cidr');
|
|
14
|
+
const getPort = require('get-port');
|
|
14
15
|
|
|
15
16
|
const logger = require('@abtnode/logger')('@abtnode/core:router:util');
|
|
16
17
|
|
|
@@ -104,6 +105,23 @@ const getGatewayPorts = (info) => {
|
|
|
104
105
|
};
|
|
105
106
|
};
|
|
106
107
|
|
|
108
|
+
/**
|
|
109
|
+
* Get available gateway ports, if the preferred ports are not available, it will return a random port
|
|
110
|
+
* This is used to avoid port conflict when validating router config
|
|
111
|
+
* Preferred ports are 8080-8085, because these ports are not used by other services
|
|
112
|
+
* @returns {Promise<{httpPort: number, httpsPort: number}>}
|
|
113
|
+
*/
|
|
114
|
+
const getAvailableGatewayPorts = async () => {
|
|
115
|
+
const preferredPorts = [8080, 8081, 8082, 8083, 8084, 8085];
|
|
116
|
+
const httpPort = await getPort({ port: preferredPorts });
|
|
117
|
+
const httpsPort = await getPort({ port: preferredPorts });
|
|
118
|
+
|
|
119
|
+
return {
|
|
120
|
+
httpPort,
|
|
121
|
+
httpsPort,
|
|
122
|
+
};
|
|
123
|
+
};
|
|
124
|
+
|
|
107
125
|
const createProviderInstance = ({ nodeInfo, routerDataDir }) => {
|
|
108
126
|
const providerName = nodeInfo.routing.provider;
|
|
109
127
|
const Provider = getProvider(providerName);
|
|
@@ -149,6 +167,7 @@ module.exports = {
|
|
|
149
167
|
getBlockletDomainGroupName,
|
|
150
168
|
getDidFromDomainGroupName,
|
|
151
169
|
getGatewayPorts,
|
|
170
|
+
getAvailableGatewayPorts,
|
|
152
171
|
updateNFTDomainRecord,
|
|
153
172
|
revokeAndDeleteNFTDomainRecord,
|
|
154
173
|
createProviderInstance,
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"publishConfig": {
|
|
4
4
|
"access": "public"
|
|
5
5
|
},
|
|
6
|
-
"version": "1.16.45-beta-
|
|
6
|
+
"version": "1.16.45-beta-20250620-082630-c0c76051",
|
|
7
7
|
"description": "",
|
|
8
8
|
"main": "lib/index.js",
|
|
9
9
|
"files": [
|
|
@@ -19,22 +19,22 @@
|
|
|
19
19
|
"author": "wangshijun <wangshijun2010@gmail.com> (http://github.com/wangshijun)",
|
|
20
20
|
"license": "Apache-2.0",
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@abtnode/analytics": "1.16.45-beta-
|
|
23
|
-
"@abtnode/auth": "1.16.45-beta-
|
|
24
|
-
"@abtnode/certificate-manager": "1.16.45-beta-
|
|
25
|
-
"@abtnode/client": "1.16.45-beta-
|
|
26
|
-
"@abtnode/constant": "1.16.45-beta-
|
|
27
|
-
"@abtnode/cron": "1.16.45-beta-
|
|
28
|
-
"@abtnode/db-cache": "1.16.45-beta-
|
|
29
|
-
"@abtnode/docker-utils": "1.16.45-beta-
|
|
30
|
-
"@abtnode/logger": "1.16.45-beta-
|
|
31
|
-
"@abtnode/models": "1.16.45-beta-
|
|
32
|
-
"@abtnode/queue": "1.16.45-beta-
|
|
33
|
-
"@abtnode/rbac": "1.16.45-beta-
|
|
34
|
-
"@abtnode/router-provider": "1.16.45-beta-
|
|
35
|
-
"@abtnode/static-server": "1.16.45-beta-
|
|
36
|
-
"@abtnode/timemachine": "1.16.45-beta-
|
|
37
|
-
"@abtnode/util": "1.16.45-beta-
|
|
22
|
+
"@abtnode/analytics": "1.16.45-beta-20250620-082630-c0c76051",
|
|
23
|
+
"@abtnode/auth": "1.16.45-beta-20250620-082630-c0c76051",
|
|
24
|
+
"@abtnode/certificate-manager": "1.16.45-beta-20250620-082630-c0c76051",
|
|
25
|
+
"@abtnode/client": "1.16.45-beta-20250620-082630-c0c76051",
|
|
26
|
+
"@abtnode/constant": "1.16.45-beta-20250620-082630-c0c76051",
|
|
27
|
+
"@abtnode/cron": "1.16.45-beta-20250620-082630-c0c76051",
|
|
28
|
+
"@abtnode/db-cache": "1.16.45-beta-20250620-082630-c0c76051",
|
|
29
|
+
"@abtnode/docker-utils": "1.16.45-beta-20250620-082630-c0c76051",
|
|
30
|
+
"@abtnode/logger": "1.16.45-beta-20250620-082630-c0c76051",
|
|
31
|
+
"@abtnode/models": "1.16.45-beta-20250620-082630-c0c76051",
|
|
32
|
+
"@abtnode/queue": "1.16.45-beta-20250620-082630-c0c76051",
|
|
33
|
+
"@abtnode/rbac": "1.16.45-beta-20250620-082630-c0c76051",
|
|
34
|
+
"@abtnode/router-provider": "1.16.45-beta-20250620-082630-c0c76051",
|
|
35
|
+
"@abtnode/static-server": "1.16.45-beta-20250620-082630-c0c76051",
|
|
36
|
+
"@abtnode/timemachine": "1.16.45-beta-20250620-082630-c0c76051",
|
|
37
|
+
"@abtnode/util": "1.16.45-beta-20250620-082630-c0c76051",
|
|
38
38
|
"@arcblock/did": "1.20.14",
|
|
39
39
|
"@arcblock/did-auth": "1.20.14",
|
|
40
40
|
"@arcblock/did-ext": "1.20.14",
|
|
@@ -45,15 +45,15 @@
|
|
|
45
45
|
"@arcblock/pm2-events": "^0.0.5",
|
|
46
46
|
"@arcblock/validator": "1.20.14",
|
|
47
47
|
"@arcblock/vc": "1.20.14",
|
|
48
|
-
"@blocklet/constant": "1.16.45-beta-
|
|
49
|
-
"@blocklet/did-space-js": "^1.0.
|
|
50
|
-
"@blocklet/env": "1.16.45-beta-
|
|
48
|
+
"@blocklet/constant": "1.16.45-beta-20250620-082630-c0c76051",
|
|
49
|
+
"@blocklet/did-space-js": "^1.0.62",
|
|
50
|
+
"@blocklet/env": "1.16.45-beta-20250620-082630-c0c76051",
|
|
51
51
|
"@blocklet/error": "^0.2.5",
|
|
52
|
-
"@blocklet/meta": "1.16.45-beta-
|
|
53
|
-
"@blocklet/resolver": "1.16.45-beta-
|
|
54
|
-
"@blocklet/sdk": "1.16.45-beta-
|
|
55
|
-
"@blocklet/store": "1.16.45-beta-
|
|
56
|
-
"@blocklet/theme": "^2.13.
|
|
52
|
+
"@blocklet/meta": "1.16.45-beta-20250620-082630-c0c76051",
|
|
53
|
+
"@blocklet/resolver": "1.16.45-beta-20250620-082630-c0c76051",
|
|
54
|
+
"@blocklet/sdk": "1.16.45-beta-20250620-082630-c0c76051",
|
|
55
|
+
"@blocklet/store": "1.16.45-beta-20250620-082630-c0c76051",
|
|
56
|
+
"@blocklet/theme": "^2.13.70",
|
|
57
57
|
"@fidm/x509": "^1.2.1",
|
|
58
58
|
"@ocap/mcrypto": "1.20.14",
|
|
59
59
|
"@ocap/util": "1.20.14",
|
|
@@ -116,5 +116,5 @@
|
|
|
116
116
|
"jest": "^29.7.0",
|
|
117
117
|
"unzipper": "^0.10.11"
|
|
118
118
|
},
|
|
119
|
-
"gitHead": "
|
|
119
|
+
"gitHead": "70151f84be54392ce491a1f40976e533286d06b8"
|
|
120
120
|
}
|