@abtnode/core 1.8.67-beta-f8b4c9ec → 1.8.67-beta-794a8082

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.
@@ -26,7 +26,6 @@ const {
26
26
  NAME_FOR_WELLKNOWN_SITE,
27
27
  DEFAULT_HTTP_PORT,
28
28
  DEFAULT_HTTPS_PORT,
29
- NODE_MODES,
30
29
  ROUTING_RULE_TYPES,
31
30
  CERTIFICATE_EXPIRES_OFFSET,
32
31
  DEFAULT_SERVICE_PATH,
@@ -56,6 +55,7 @@ const {
56
55
  findInterfacePortByName,
57
56
  getWellknownSitePort,
58
57
  getServerDidDomain,
58
+ isGatewayCacheEnabled,
59
59
  } = require('../util');
60
60
  const { getIpDnsDomainForBlocklet, getDidDomainForBlocklet } = require('../util/get-domain-for-blocklet');
61
61
  const { getFromCache: getAccessibleExternalNodeIp } = require('../util/get-accessible-external-node-ip');
@@ -382,7 +382,7 @@ const ensureBlockletCache = async (sites = [], blocklets) => {
382
382
  const clone = cloneDeep(rule);
383
383
  clone.from.pathPrefix = joinUrl(rule.from.pathPrefix, cachePrefix);
384
384
  clone.to.cacheGroup = 'blockletProxy';
385
- clone.to.target = cachePrefix;
385
+ clone.to.targetPrefix = cachePrefix;
386
386
  clone.dynamic = true; // mark as dynamic to avoid redundant generated rules
387
387
  cacheRules.push(clone);
388
388
  });
@@ -1115,7 +1115,7 @@ module.exports = function getRouterHelpers({ dataDirs, routingSnapshot, routerMa
1115
1115
  configDir: path.join(dataDirs.router, providerName),
1116
1116
  httpPort: nodeInfo.routing.httpPort || DEFAULT_HTTP_PORT,
1117
1117
  httpsPort: nodeInfo.routing.httpsPort || DEFAULT_HTTPS_PORT,
1118
- cacheDisabled: nodeInfo.mode === NODE_MODES.DEBUG,
1118
+ cacheEnabled: isGatewayCacheEnabled(nodeInfo),
1119
1119
  }),
1120
1120
  getRoutingParams: async () => {
1121
1121
  try {
@@ -1220,7 +1220,7 @@ module.exports = function getRouterHelpers({ dataDirs, routingSnapshot, routerMa
1220
1220
  configDir: path.join(dataDirs.router, info.routing.provider),
1221
1221
  httpPort: info.routing.httpPort || DEFAULT_HTTP_PORT,
1222
1222
  httpsPort: info.routing.httpsPort || DEFAULT_HTTPS_PORT,
1223
- cacheDisabled: info.mode === NODE_MODES.DEBUG,
1223
+ cacheEnabled: isGatewayCacheEnabled(info),
1224
1224
  });
1225
1225
  await providerInstance.stop();
1226
1226
  logger.info('original router stopped:', { provider: info.routing.provider });
@@ -1408,6 +1408,8 @@ module.exports = function getRouterHelpers({ dataDirs, routingSnapshot, routerMa
1408
1408
  deleteRoutingRule,
1409
1409
  addDomainAlias,
1410
1410
  deleteDomainAlias,
1411
+
1412
+ isGatewayCacheEnabled,
1411
1413
  };
1412
1414
  };
1413
1415
 
@@ -11,8 +11,11 @@ const {
11
11
  GATEWAY_REQ_LIMIT,
12
12
  } = require('@abtnode/constant');
13
13
  const { BLOCKLET_UI_INTERFACES, BLOCKLET_MODES } = require('@blocklet/constant');
14
+
14
15
  const logger = require('@abtnode/logger')('@abtnode/core:router');
15
16
 
17
+ const { isGatewayCacheEnabled } = require('../util');
18
+
16
19
  const expandSites = (sites = []) => {
17
20
  const result = [];
18
21
 
@@ -117,6 +120,7 @@ class Router {
117
120
  services,
118
121
  nodeInfo: pick(nodeInfo, ['name', 'version', 'port', 'mode', 'enableWelcomePage', 'routing']),
119
122
  requestLimit,
123
+ cacheEnabled: isGatewayCacheEnabled(nodeInfo),
120
124
  });
121
125
  }
122
126
 
@@ -559,8 +559,8 @@ class RouterManager extends EventEmitter {
559
559
  await tempRouter.validateConfig();
560
560
  await fse.remove(tmpDir);
561
561
  } catch (error) {
562
+ // 如果出错,保留 Nginx 配置文件,方便定位问题
562
563
  logger.error('validate router config failed', { error, action, data });
563
- await fse.remove(tmpDir);
564
564
  throw error;
565
565
  }
566
566
  }
@@ -239,9 +239,11 @@ const getLogContent = async (action, args, context, result, info, node) => {
239
239
  case 'deleteRoutingRule':
240
240
  return `deleted routing rule from ${site}`; // prettier-ignore
241
241
  case 'updateGateway': {
242
- let message = args.requestLimit.enabled ? `status: enabled, rate: ${args.requestLimit.rate}` : 'status: disabled';
243
- message = `update gateway. ${message}`;
244
-
242
+ const changes = [
243
+ args.requestLimit.enabled ? `rate limit: enabled, rate: ${args.requestLimit.rate}` : 'rate limit: disabled',
244
+ args.cacheEnabled ? `global cache: enabled, rate: ${args.cacheEnabled}` : 'global cache: disabled',
245
+ ];
246
+ const message = `update gateway: ${changes.join('; ')}`;
245
247
  return message;
246
248
  }
247
249
  case 'createTransferInvitation':
@@ -310,7 +310,10 @@ class NodeState extends BaseState {
310
310
  }
311
311
 
312
312
  async updateGateway(gateway) {
313
- const [, nodeInfo] = await this.update({}, { $set: { 'routing.requestLimit': gateway.requestLimit } });
313
+ const [, nodeInfo] = await this.update(
314
+ {},
315
+ { $set: { 'routing.requestLimit': gateway.requestLimit, 'routing.cacheEnabled': gateway.cacheEnabled } }
316
+ );
314
317
 
315
318
  this.emit(EVENTS.RELOAD_GATEWAY, nodeInfo);
316
319
 
@@ -94,6 +94,7 @@ const {
94
94
  validateBlockletMeta,
95
95
  prettyURL,
96
96
  getNFTState,
97
+ templateReplace,
97
98
  } = require('./index');
98
99
 
99
100
  const getComponentConfig = (meta) => meta.components || meta.children;
@@ -240,12 +241,12 @@ const getComponentDirs = (
240
241
  const fillBlockletConfigs = (blocklet, configs) => {
241
242
  blocklet.configs = configs || [];
242
243
  blocklet.configObj = blocklet.configs.reduce((acc, x) => {
243
- acc[x.key] = x.value;
244
+ acc[x.key] = templateReplace(x.value, blocklet);
244
245
  return acc;
245
246
  }, {});
246
247
  blocklet.environments = blocklet.environments || [];
247
248
  blocklet.environmentObj = blocklet.environments.reduce((acc, x) => {
248
- acc[x.key] = x.value;
249
+ acc[x.key] = templateReplace(x.value, blocklet);
249
250
  return acc;
250
251
  }, {});
251
252
  };
package/lib/util/index.js CHANGED
@@ -27,6 +27,7 @@ const {
27
27
  DEFAULT_HTTP_PORT,
28
28
  DEFAULT_HTTPS_PORT,
29
29
  SLOT_FOR_IP_DNS_SITE,
30
+ NODE_MODES,
30
31
  } = require('@abtnode/constant');
31
32
 
32
33
  const DEFAULT_WELLKNOWN_PORT = 8088;
@@ -452,6 +453,27 @@ const prettyURL = (url, isHttps = true) => {
452
453
  return isHttps ? `https://${url}` : `http://${url}`;
453
454
  };
454
455
 
456
+ const templateReplace = (str, vars = {}) => {
457
+ if (typeof str === 'string') {
458
+ return str.replace(/{([.\w]+)}/g, (m, key) => get(vars, key));
459
+ }
460
+
461
+ return str;
462
+ };
463
+
464
+ const isGatewayCacheEnabled = (info) => {
465
+ if (info.mode === NODE_MODES.DEBUG) {
466
+ return false;
467
+ }
468
+
469
+ const cacheEnabled = get(info, 'routing.cacheEnabled');
470
+ if (typeof cacheEnabled === 'boolean') {
471
+ return cacheEnabled;
472
+ }
473
+
474
+ return true;
475
+ };
476
+
455
477
  const lib = {
456
478
  validateOwner,
457
479
  getProviderFromNodeInfo,
@@ -489,6 +511,8 @@ const lib = {
489
511
  getNFTState,
490
512
  getServerDidDomain,
491
513
  prettyURL,
514
+ templateReplace,
515
+ isGatewayCacheEnabled,
492
516
  };
493
517
 
494
518
  module.exports = lib;
@@ -52,6 +52,7 @@ const updateGatewaySchema = Joi.object({
52
52
  .when('requestLimit.enabled', { is: true, then: Joi.required() }),
53
53
  ipHeader: Joi.string().allow('').trim(),
54
54
  }),
55
+ cacheEnabled: Joi.bool().optional().default(true),
55
56
  });
56
57
 
57
58
  module.exports = {
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "1.8.67-beta-f8b4c9ec",
6
+ "version": "1.8.67-beta-794a8082",
7
7
  "description": "",
8
8
  "main": "lib/index.js",
9
9
  "files": [
@@ -19,18 +19,18 @@
19
19
  "author": "wangshijun <wangshijun2010@gmail.com> (http://github.com/wangshijun)",
20
20
  "license": "MIT",
21
21
  "dependencies": {
22
- "@abtnode/auth": "1.8.67-beta-f8b4c9ec",
23
- "@abtnode/certificate-manager": "1.8.67-beta-f8b4c9ec",
24
- "@abtnode/constant": "1.8.67-beta-f8b4c9ec",
25
- "@abtnode/cron": "1.8.67-beta-f8b4c9ec",
26
- "@abtnode/db": "1.8.67-beta-f8b4c9ec",
27
- "@abtnode/logger": "1.8.67-beta-f8b4c9ec",
28
- "@abtnode/queue": "1.8.67-beta-f8b4c9ec",
29
- "@abtnode/rbac": "1.8.67-beta-f8b4c9ec",
30
- "@abtnode/router-provider": "1.8.67-beta-f8b4c9ec",
31
- "@abtnode/static-server": "1.8.67-beta-f8b4c9ec",
32
- "@abtnode/timemachine": "1.8.67-beta-f8b4c9ec",
33
- "@abtnode/util": "1.8.67-beta-f8b4c9ec",
22
+ "@abtnode/auth": "1.8.67-beta-794a8082",
23
+ "@abtnode/certificate-manager": "1.8.67-beta-794a8082",
24
+ "@abtnode/constant": "1.8.67-beta-794a8082",
25
+ "@abtnode/cron": "1.8.67-beta-794a8082",
26
+ "@abtnode/db": "1.8.67-beta-794a8082",
27
+ "@abtnode/logger": "1.8.67-beta-794a8082",
28
+ "@abtnode/queue": "1.8.67-beta-794a8082",
29
+ "@abtnode/rbac": "1.8.67-beta-794a8082",
30
+ "@abtnode/router-provider": "1.8.67-beta-794a8082",
31
+ "@abtnode/static-server": "1.8.67-beta-794a8082",
32
+ "@abtnode/timemachine": "1.8.67-beta-794a8082",
33
+ "@abtnode/util": "1.8.67-beta-794a8082",
34
34
  "@arcblock/did": "1.18.54",
35
35
  "@arcblock/did-motif": "^1.1.10",
36
36
  "@arcblock/did-util": "1.18.54",
@@ -38,9 +38,9 @@
38
38
  "@arcblock/jwt": "^1.18.54",
39
39
  "@arcblock/pm2-events": "^0.0.5",
40
40
  "@arcblock/vc": "1.18.54",
41
- "@blocklet/constant": "1.8.67-beta-f8b4c9ec",
42
- "@blocklet/meta": "1.8.67-beta-f8b4c9ec",
43
- "@blocklet/sdk": "1.8.67-beta-f8b4c9ec",
41
+ "@blocklet/constant": "1.8.67-beta-794a8082",
42
+ "@blocklet/meta": "1.8.67-beta-794a8082",
43
+ "@blocklet/sdk": "1.8.67-beta-794a8082",
44
44
  "@did-space/client": "^0.1.76",
45
45
  "@fidm/x509": "^1.2.1",
46
46
  "@ocap/mcrypto": "1.18.54",
@@ -89,5 +89,5 @@
89
89
  "express": "^4.18.2",
90
90
  "jest": "^27.5.1"
91
91
  },
92
- "gitHead": "ebf19fcbc6d99fff0d214dc0680c4df81aa94d6d"
92
+ "gitHead": "f4ad32bea4d80b12971fb6bef941bdbe2af6a834"
93
93
  }