@abtnode/router-provider 1.8.60 → 1.8.62

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.
@@ -159,6 +159,10 @@ class DefaultProvider extends BaseProvider {
159
159
  error: fs.realpathSync(this.errorLog),
160
160
  };
161
161
  }
162
+
163
+ getLogDir() {
164
+ return this.logDir;
165
+ }
162
166
  }
163
167
 
164
168
  DefaultProvider.describe = async ({ configDir = '' } = {}) => {
@@ -131,6 +131,10 @@ class NginxProvider extends BaseProvider {
131
131
  this.initialize();
132
132
  }
133
133
 
134
+ static isDidAuthPrefix(prefix) {
135
+ return prefix === ADMIN_DID_AUTH_PATH_PREFIX;
136
+ }
137
+
134
138
  getRelativeConfigDir(dir) {
135
139
  return path.relative(this.configDir, dir);
136
140
  }
@@ -449,23 +453,10 @@ class NginxProvider extends BaseProvider {
449
453
  server._add('location', concatPath(prefix, suffix));
450
454
 
451
455
  const location = this._getLastLocation(server);
452
- const isDidAuthPath = prefix === ADMIN_DID_AUTH_PATH_PREFIX;
456
+ const isDidAuthPath = NginxProvider.isDidAuthPrefix(prefix);
453
457
 
454
458
  // Note: 下面这段代码比较 tricky,不要在这段代码之前添加任何 add_header, proxy_set_header, proxy_hide_header 的语句,否则 nginx 配置可能无法按预期工作
455
- if (!isEmpty(corsAllowedOrigins)) {
456
- if (corsAllowedOrigins.includes(DOMAIN_FOR_DEFAULT_SITE) || isDidAuthPath) {
457
- location._add('include', 'includes/cors-loose');
458
- location._add('include', 'includes/security');
459
- } else {
460
- location._add('add_header', `Access-Control-Allow-Origin $allow_origin_${md5(serverName)} always`);
461
- location._add('include', 'includes/cors-strict');
462
- location._add('include', 'includes/security');
463
- }
464
-
465
- location._addVerbatimBlock('if ($request_method = "OPTIONS")', 'return 204;');
466
- } else {
467
- location._add('include', 'includes/security');
468
- }
459
+ this._addCors({ location, corsAllowedOrigins, serverName, isDidAuthPath });
469
460
 
470
461
  this._addCommonResHeaders(location, commonHeaders);
471
462
  this._addTailSlashRedirection(location, prefix); // Note: 末尾 "/" 的重定向要放在 CORS(OPTIONS) 响应之后, 这样不会影响 OPTIONS 的响应
@@ -522,11 +513,15 @@ class NginxProvider extends BaseProvider {
522
513
  location._add('proxy_pass', `http://${getUpstreamName(port)}`);
523
514
  }
524
515
 
525
- _addRedirectTypeLocation({ server, url, redirectCode, prefix, suffix }) {
516
+ _addRedirectTypeLocation({ server, url, redirectCode, prefix, suffix, corsAllowedOrigins, serverName }) {
526
517
  const cleanUrl = trimEndSlash(url);
527
-
528
518
  server._add('location', `${concatPath(prefix, suffix)}`);
529
519
  const location = this._getLastLocation(server);
520
+
521
+ const isDidAuthPath = NginxProvider.isDidAuthPrefix(prefix);
522
+
523
+ this._addCors({ location, corsAllowedOrigins, serverName, isDidAuthPath });
524
+
530
525
  location._add('set $abt_query_string', '""');
531
526
  location._addVerbatimBlock('if ($query_string)', 'set $abt_query_string "?$query_string";');
532
527
 
@@ -739,7 +734,7 @@ class NginxProvider extends BaseProvider {
739
734
 
740
735
  this._addDefaultLocations(httpsServerUnit, daemonPort);
741
736
  // eslint-disable-next-line max-len
742
- locations.forEach((x) => this._addReverseProxy({ server: httpsServerUnit, ...x, serverName, corsAllowedOrigins,commonHeaders })); // prettier-ignore
737
+ locations.forEach((x) => this._addReverseProxy({ server: httpsServerUnit, ...x, serverName, corsAllowedOrigins, commonHeaders })); // prettier-ignore
743
738
  }
744
739
 
745
740
  _addHttpServerUnit({ conf, serverName, port }) {
@@ -832,6 +827,23 @@ class NginxProvider extends BaseProvider {
832
827
  });
833
828
  }
834
829
 
830
+ _addCors({ location, corsAllowedOrigins, serverName, isDidAuthPath }) {
831
+ if (!isEmpty(corsAllowedOrigins)) {
832
+ if (corsAllowedOrigins.includes(DOMAIN_FOR_DEFAULT_SITE) || isDidAuthPath) {
833
+ location._add('include', 'includes/cors-loose');
834
+ location._add('include', 'includes/security');
835
+ } else {
836
+ location._add('add_header', `Access-Control-Allow-Origin $allow_origin_${md5(serverName)} always`);
837
+ location._add('include', 'includes/cors-strict');
838
+ location._add('include', 'includes/security');
839
+ }
840
+
841
+ location._addVerbatimBlock('if ($request_method = "OPTIONS")', 'return 204;');
842
+ } else {
843
+ location._add('include', 'includes/security');
844
+ }
845
+ }
846
+
835
847
  addGlobalReqLimit(block, limit) {
836
848
  const key = limit.ipHeader ? `$http_${limit.ipHeader}` : '$binary_remote_addr';
837
849
  block._add('limit_req_zone', `${key} zone=ip_limit:20m rate=${limit.rate || 5}r/s`);
@@ -845,6 +857,10 @@ class NginxProvider extends BaseProvider {
845
857
  error: this.errorLog,
846
858
  };
847
859
  }
860
+
861
+ getLogDir() {
862
+ return this.logDir;
863
+ }
848
864
  }
849
865
 
850
866
  NginxProvider.describe = async ({ configDir = '' } = {}) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@abtnode/router-provider",
3
- "version": "1.8.60",
3
+ "version": "1.8.62",
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.60",
36
- "@abtnode/logger": "1.8.60",
37
- "@abtnode/router-templates": "1.8.60",
38
- "@abtnode/util": "1.8.60",
35
+ "@abtnode/constant": "1.8.62",
36
+ "@abtnode/logger": "1.8.62",
37
+ "@abtnode/router-templates": "1.8.62",
38
+ "@abtnode/util": "1.8.62",
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": "0a56dc596f58d83f22d1ea0d0145d84e7151f5be"
65
+ "gitHead": "ea6ab48149eb9e1157ef37ab1505fa36a9ce598f"
66
66
  }