@abtnode/router-provider 1.7.11 → 1.7.12

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.
Files changed (2) hide show
  1. package/lib/nginx/index.js +18 -1
  2. package/package.json +6 -6
@@ -126,7 +126,14 @@ class NginxProvider extends BaseProvider {
126
126
  this.initialize();
127
127
  }
128
128
 
129
- async update({ routingTable = [], certificates = [], commonHeaders, services = [], nodeInfo = {} } = {}) {
129
+ async update({
130
+ routingTable = [],
131
+ certificates = [],
132
+ commonHeaders,
133
+ services = [],
134
+ nodeInfo = {},
135
+ requestLimit,
136
+ } = {}) {
130
137
  if (!Array.isArray(routingTable)) {
131
138
  throw new Error('routingTable must be an array');
132
139
  }
@@ -165,6 +172,9 @@ class NginxProvider extends BaseProvider {
165
172
  conf.nginx.http._add('server_tokens', 'off');
166
173
  this._addCommonResHeaders(conf.nginx.http, commonHeaders);
167
174
  this._addExposeServices(conf, services);
175
+ if (requestLimit && requestLimit.enabled) {
176
+ this.addGlobalReqLimit(conf.nginx.http, requestLimit);
177
+ }
168
178
 
169
179
  logger.info('routing sites:', sites);
170
180
  // eslint-disable-next-line no-restricted-syntax
@@ -762,6 +772,13 @@ class NginxProvider extends BaseProvider {
762
772
  });
763
773
  }
764
774
 
775
+ addGlobalReqLimit(block, limit) {
776
+ const key = limit.ipHeader ? `$http_${limit.ipHeader}` : '$binary_remote_addr';
777
+ block._add('limit_req_zone', `${key} zone=ip_limit:20m rate=${limit.rate || 5}r/s`);
778
+ block._add('limit_req', `zone=ip_limit burst=${limit.maxInstantRate || 30} delay=10`);
779
+ block._add('limit_req_status', 429);
780
+ }
781
+
765
782
  getLogFilesForToday() {
766
783
  return {
767
784
  access: this.accessLog,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@abtnode/router-provider",
3
- "version": "1.7.11",
3
+ "version": "1.7.12",
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.7.11",
36
- "@abtnode/logger": "1.7.11",
37
- "@abtnode/router-templates": "1.7.11",
38
- "@abtnode/util": "1.7.11",
35
+ "@abtnode/constant": "1.7.12",
36
+ "@abtnode/logger": "1.7.12",
37
+ "@abtnode/router-templates": "1.7.12",
38
+ "@abtnode/util": "1.7.12",
39
39
  "axios": "^0.26.1",
40
40
  "debug": "^4.3.3",
41
41
  "find-process": "^1.4.3",
@@ -62,5 +62,5 @@
62
62
  "fs-extra": "^10.0.1",
63
63
  "needle": "^3.0.0"
64
64
  },
65
- "gitHead": "84e741e6b37e47d52bf834ce3ace8ed601d0896c"
65
+ "gitHead": "afc78b9cb92448676149262fb02432bc256a5524"
66
66
  }