@abtnode/router-provider 1.8.68 → 1.8.69-beta-e0666d0d

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.
@@ -79,12 +79,14 @@ const parseServerName = (domain) => {
79
79
 
80
80
  class NginxProvider extends BaseProvider {
81
81
  /**
82
- * @param {string} configDir
83
- * @param {number} httpPort
84
- * @param {number} httpPort
85
- * @param {number} cacheDisabled
82
+ * @param {object} options
83
+ * @param {string} options.configDir
84
+ * @param {number} options.httpPort
85
+ * @param {number} options.httpsPort
86
+ * @param {boolean} [options.cacheEnabled]
87
+ * @param {boolean} [options.isTest]
86
88
  */
87
- constructor({ configDir, httpPort, httpsPort, cacheDisabled, isTest }) {
89
+ constructor({ configDir, httpPort, httpsPort, cacheEnabled = true, isTest = false }) {
88
90
  super('nginx');
89
91
  if (!configDir) {
90
92
  throw new Error('invalid configDir');
@@ -111,7 +113,7 @@ class NginxProvider extends BaseProvider {
111
113
 
112
114
  this.httpPort = decideHttpPort(httpPort);
113
115
  this.httpsPort = decideHttpsPort(httpsPort);
114
- this.cacheDisabled = !!cacheDisabled;
116
+ this.cacheEnabled = !!cacheEnabled;
115
117
  this.isHttp2Supported = this._isHttp2Supported();
116
118
  this.conf = null; // nginx `conf` object
117
119
 
@@ -119,7 +121,7 @@ class NginxProvider extends BaseProvider {
119
121
  configDir,
120
122
  httpPort: this.httpPort,
121
123
  httpsPort: this.httpsPort,
122
- cacheDisabled: this.cacheDisabled,
124
+ cacheEnabled: this.cacheEnabled,
123
125
  });
124
126
 
125
127
  // ensure directories
@@ -159,11 +161,16 @@ class NginxProvider extends BaseProvider {
159
161
  services = [],
160
162
  nodeInfo = {},
161
163
  requestLimit,
164
+ cacheEnabled,
162
165
  } = {}) {
163
166
  if (!Array.isArray(routingTable)) {
164
167
  throw new Error('routingTable must be an array');
165
168
  }
166
169
 
170
+ if (typeof cacheEnabled !== 'undefined') {
171
+ this.cacheEnabled = !!cacheEnabled;
172
+ }
173
+
167
174
  this._addWwwFiles(nodeInfo);
168
175
 
169
176
  // eslint-disable-next-line consistent-return
@@ -432,12 +439,6 @@ class NginxProvider extends BaseProvider {
432
439
  * rewrite ^/flash/(.*) /$1 break;
433
440
  * proxy_pass http://127.0.0.1:8090;
434
441
  * }
435
- * @param {object} server
436
- * @param {number} port
437
- * @param {string} pathPrefix
438
- * @param {string} pathSuffix
439
- * @param {string} did app did
440
- * @param {string} componentId component id
441
442
  */
442
443
  _addBlockletTypeLocation({
443
444
  server,
@@ -450,6 +451,7 @@ class NginxProvider extends BaseProvider {
450
451
  componentId,
451
452
  corsAllowedOrigins,
452
453
  target,
454
+ targetPrefix, // used to strip prefix from target
453
455
  ruleId,
454
456
  type,
455
457
  commonHeaders,
@@ -471,14 +473,15 @@ class NginxProvider extends BaseProvider {
471
473
  if (did) {
472
474
  location._add('set', `$did "${did}"`);
473
475
  location._add('proxy_set_header', `X-Blocklet-Did "${did}"`);
474
- location._add('proxy_set_header', `X-Blocklet-Component-Id "${componentId}"`);
476
+ if (componentId) {
477
+ location._add('proxy_set_header', `X-Blocklet-Component-Id "${componentId}"`);
478
+ }
475
479
  }
476
480
 
477
481
  location._add('include', 'includes/proxy');
478
482
 
479
483
  // kill cache
480
- // TODO: 这个放在管理端的 Gateway 配置中
481
- if (this.cacheDisabled) {
484
+ if (this.cacheEnabled === false) {
482
485
  location._add('expires', '-1');
483
486
  } else if (ROUTER_CACHE_GROUPS[cacheGroup]) {
484
487
  location._add('proxy_cache', cacheGroup);
@@ -489,9 +492,12 @@ class NginxProvider extends BaseProvider {
489
492
  // Redirect blocklet traffic
490
493
  if (type === ROUTING_RULE_TYPES.BLOCKLET) {
491
494
  // FIXME: logic related to server gateway should not in provider
492
- const rewritePathPrefix = prefix.replace(WELLKNOWN_SERVICE_PATH_PREFIX, '').replace(USER_AVATAR_PATH_PREFIX, '');
495
+ let rewritePathPrefix = prefix.replace(WELLKNOWN_SERVICE_PATH_PREFIX, '').replace(USER_AVATAR_PATH_PREFIX, '');
493
496
 
494
497
  // Add header
498
+ if (targetPrefix) {
499
+ rewritePathPrefix = rewritePathPrefix.replace(targetPrefix, '');
500
+ }
495
501
 
496
502
  location._add('proxy_set_header', `X-Path-Prefix "${rewritePathPrefix}"`);
497
503
  if (groupPrefix) {
package/lib/util.js CHANGED
@@ -55,7 +55,11 @@ const formatRoutingTable = (routingTable, onRule) => {
55
55
  domain = '_';
56
56
  }
57
57
 
58
- configs.push({ domain, corsAllowedOrigins: site.corsAllowedOrigins });
58
+ let corsAllowedOrigins = Array.isArray(site.corsAllowedOrigins) ? site.corsAllowedOrigins : [];
59
+ if (corsAllowedOrigins.includes('*')) {
60
+ corsAllowedOrigins = ['*'];
61
+ }
62
+ configs.push({ domain, corsAllowedOrigins });
59
63
 
60
64
  if (!sites[domain]) {
61
65
  sites[domain] = {
@@ -89,6 +93,7 @@ const formatRoutingTable = (routingTable, onRule) => {
89
93
  rule.cacheGroup = x.to.cacheGroup;
90
94
  rule.componentId = x.to.componentId;
91
95
  rule.target = trimEndSlash(normalizePathPrefix(x.to.target || '/'));
96
+ rule.targetPrefix = x.to.targetPrefix || '';
92
97
  rule.services = x.services || [];
93
98
  }
94
99
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@abtnode/router-provider",
3
- "version": "1.8.68",
3
+ "version": "1.8.69-beta-e0666d0d",
4
4
  "description": "Routing engine implementations for abt node",
5
5
  "author": "polunzh <polunzh@gmail.com>",
6
6
  "homepage": "https://github.com/ArcBlock/blocklet-server#readme",
@@ -32,10 +32,10 @@
32
32
  "url": "https://github.com/ArcBlock/blocklet-server/issues"
33
33
  },
34
34
  "dependencies": {
35
- "@abtnode/constant": "1.8.68",
36
- "@abtnode/logger": "1.8.68",
37
- "@abtnode/router-templates": "1.8.68",
38
- "@abtnode/util": "1.8.68",
35
+ "@abtnode/constant": "1.8.69-beta-e0666d0d",
36
+ "@abtnode/logger": "1.8.69-beta-e0666d0d",
37
+ "@abtnode/router-templates": "1.8.69-beta-e0666d0d",
38
+ "@abtnode/util": "1.8.69-beta-e0666d0d",
39
39
  "axios": "^0.27.2",
40
40
  "debug": "^4.3.4",
41
41
  "find-process": "^1.4.7",
@@ -62,5 +62,5 @@
62
62
  "fs-extra": "^10.1.0",
63
63
  "needle": "^3.1.0"
64
64
  },
65
- "gitHead": "1392044ac5677bde567797adeb9a6d3f0b9264b8"
65
+ "gitHead": "acf0373591eaa3aff76483edc4e648afc543f1f7"
66
66
  }