@abtnode/router-provider 1.6.25 → 1.6.28
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/default/daemon.js +16 -5
- package/lib/nginx/index.js +24 -20
- package/package.json +6 -6
package/lib/default/daemon.js
CHANGED
|
@@ -4,7 +4,11 @@ const fs = require('fs-extra');
|
|
|
4
4
|
const get = require('lodash/get');
|
|
5
5
|
const joinUrl = require('url-join');
|
|
6
6
|
const checkDomainMatch = require('@abtnode/util/lib/check-domain-match');
|
|
7
|
-
const {
|
|
7
|
+
const {
|
|
8
|
+
DEFAULT_IP_DNS_DOMAIN_SUFFIX,
|
|
9
|
+
ROUTING_RULE_TYPES,
|
|
10
|
+
WELLKNOWN_SERVICE_PATH_PREFIX,
|
|
11
|
+
} = require('@abtnode/constant');
|
|
8
12
|
|
|
9
13
|
const logger = require('@abtnode/logger')('router:default:daemon', { filename: 'engine' });
|
|
10
14
|
|
|
@@ -61,10 +65,13 @@ const createRequestHandler = (id) => (req, res, target) => {
|
|
|
61
65
|
}
|
|
62
66
|
}
|
|
63
67
|
|
|
68
|
+
// FIXME logic related to server gateway should not in provider
|
|
69
|
+
const rewritePathPrefix = rule.prefix.replace(WELLKNOWN_SERVICE_PATH_PREFIX, '') || '/';
|
|
70
|
+
|
|
64
71
|
if (rule.type === ROUTING_RULE_TYPES.GENERAL_PROXY) {
|
|
65
72
|
// we do not need rewrite for internal servers
|
|
66
73
|
} else {
|
|
67
|
-
req.url =
|
|
74
|
+
req.url = req.url.substr(rewritePathPrefix.length);
|
|
68
75
|
}
|
|
69
76
|
|
|
70
77
|
if (req.url.startsWith('/') === false) {
|
|
@@ -79,16 +86,20 @@ const createRequestHandler = (id) => (req, res, target) => {
|
|
|
79
86
|
req.headers['X-Blocklet-Real-Did'] = rule.realDid;
|
|
80
87
|
}
|
|
81
88
|
|
|
82
|
-
req.headers['X-Path-Prefix'] =
|
|
89
|
+
req.headers['X-Path-Prefix'] = rewritePathPrefix;
|
|
83
90
|
req.headers['X-Group-Path-Prefix'] = rule.groupPrefix || '/';
|
|
84
91
|
|
|
85
|
-
if (rule.
|
|
92
|
+
if (rule.type === ROUTING_RULE_TYPES.BLOCKLET) {
|
|
86
93
|
req.headers['X-Blocklet-Url'] = `http://127.0.0.1:${rule.port}`;
|
|
87
94
|
}
|
|
88
95
|
|
|
89
96
|
if (rule.ruleId) {
|
|
90
97
|
req.headers['X-Routing-Rule-Id'] = rule.ruleId;
|
|
91
98
|
}
|
|
99
|
+
|
|
100
|
+
if (rule.target && rule.target !== '/') {
|
|
101
|
+
req.headers['X-Routing-Rule-Path-Prefix'] = rule.target;
|
|
102
|
+
}
|
|
92
103
|
};
|
|
93
104
|
|
|
94
105
|
// eslint-disable-next-line
|
|
@@ -116,7 +127,7 @@ const sharedResolver = (host, url, req) => {
|
|
|
116
127
|
}
|
|
117
128
|
|
|
118
129
|
const match = findCertificate(config.certs, domain);
|
|
119
|
-
const upstream = `http://127.0.0.1:${rule.
|
|
130
|
+
const upstream = `http://127.0.0.1:${rule.type === ROUTING_RULE_TYPES.BLOCKLET ? servicePort : rule.port}`;
|
|
120
131
|
logger.debug('resolved request', { host, url, domain, upstream, rule });
|
|
121
132
|
|
|
122
133
|
return {
|
package/lib/nginx/index.js
CHANGED
|
@@ -16,7 +16,7 @@ const {
|
|
|
16
16
|
CONFIG_FOLDER_NAME,
|
|
17
17
|
DEFAULT_ADMIN_PATH,
|
|
18
18
|
SLOT_FOR_IP_DNS_SITE,
|
|
19
|
-
|
|
19
|
+
WELLKNOWN_SERVICE_PATH_PREFIX,
|
|
20
20
|
} = require('@abtnode/constant');
|
|
21
21
|
const md5 = require('@abtnode/util/lib/md5');
|
|
22
22
|
|
|
@@ -51,7 +51,7 @@ const {
|
|
|
51
51
|
const REQUIRED_MODULES = [{ configName: 'with-stream', moduleBinaryName: 'ngx_stream_module.so' }];
|
|
52
52
|
|
|
53
53
|
// TODO: move the did-auth-path-prefix to a constant
|
|
54
|
-
const
|
|
54
|
+
const ADMIN_DID_AUTH_PATH_PREFIX = `${DEFAULT_ADMIN_PATH}/api/did`;
|
|
55
55
|
|
|
56
56
|
// convert wildcard domain and ipDnsDomain template to regex
|
|
57
57
|
const parseServerName = (domain) => {
|
|
@@ -154,7 +154,7 @@ class NginxProvider extends BaseProvider {
|
|
|
154
154
|
// TODO: this is really hacky, and should be abstracted out
|
|
155
155
|
if (rule.type === ROUTING_RULE_TYPES.DAEMON && rule.prefix === DEFAULT_ADMIN_PATH) {
|
|
156
156
|
const clonedRule = cloneDeep(rule);
|
|
157
|
-
clonedRule.prefix =
|
|
157
|
+
clonedRule.prefix = ADMIN_DID_AUTH_PATH_PREFIX;
|
|
158
158
|
rules.push(clonedRule);
|
|
159
159
|
}
|
|
160
160
|
});
|
|
@@ -318,7 +318,9 @@ class NginxProvider extends BaseProvider {
|
|
|
318
318
|
return parseNginxConfigArgs(result.stderr);
|
|
319
319
|
}
|
|
320
320
|
|
|
321
|
-
_addReverseProxy(
|
|
321
|
+
_addReverseProxy(args) {
|
|
322
|
+
const { type } = args;
|
|
323
|
+
|
|
322
324
|
if (type === ROUTING_RULE_TYPES.REDIRECT) {
|
|
323
325
|
this._addRedirectTypeLocation(args);
|
|
324
326
|
return;
|
|
@@ -370,13 +372,12 @@ class NginxProvider extends BaseProvider {
|
|
|
370
372
|
corsAllowedOrigins,
|
|
371
373
|
target,
|
|
372
374
|
ruleId,
|
|
373
|
-
|
|
375
|
+
type,
|
|
374
376
|
}) {
|
|
375
377
|
server._add('location', concatPath(prefix, suffix));
|
|
376
378
|
|
|
377
379
|
const location = this._getLastLocation(server);
|
|
378
|
-
const isDidAuthPath = prefix ===
|
|
379
|
-
const rewritePathPrefix = isDidAuthPath ? DEFAULT_ADMIN_PATH : prefix;
|
|
380
|
+
const isDidAuthPath = prefix === ADMIN_DID_AUTH_PATH_PREFIX;
|
|
380
381
|
|
|
381
382
|
// Note: 下面这段代码比较 tricky,不要在这段代码之前添加任何 add_header, proxy_set_header, proxy_hide_header 的语句,否则 nginx 配置可能无法按预期工作
|
|
382
383
|
if (!isEmpty(corsAllowedOrigins)) {
|
|
@@ -410,14 +411,19 @@ class NginxProvider extends BaseProvider {
|
|
|
410
411
|
}
|
|
411
412
|
|
|
412
413
|
location._add('include', 'includes/proxy');
|
|
413
|
-
location._add('proxy_set_header', `X-Path-Prefix "${rewritePathPrefix}"`);
|
|
414
|
-
if (groupPrefix) {
|
|
415
|
-
location._add('proxy_set_header', `X-Group-Path-Prefix "${groupPrefix}"`);
|
|
416
|
-
}
|
|
417
414
|
|
|
418
|
-
// Redirect traffic
|
|
419
|
-
if (
|
|
415
|
+
// Redirect blocklet traffic
|
|
416
|
+
if (type === ROUTING_RULE_TYPES.BLOCKLET) {
|
|
417
|
+
// FIXME logic related to server gateway should not in provider
|
|
418
|
+
const rewritePathPrefix = prefix.replace(WELLKNOWN_SERVICE_PATH_PREFIX, '') || '/';
|
|
419
|
+
|
|
420
420
|
// Add header
|
|
421
|
+
|
|
422
|
+
location._add('proxy_set_header', `X-Path-Prefix "${rewritePathPrefix}"`);
|
|
423
|
+
if (groupPrefix) {
|
|
424
|
+
location._add('proxy_set_header', `X-Group-Path-Prefix "${groupPrefix}"`);
|
|
425
|
+
}
|
|
426
|
+
|
|
421
427
|
location._add('proxy_set_header', `X-Blocklet-Url "http://127.0.0.1:${port}"`);
|
|
422
428
|
if (ruleId) {
|
|
423
429
|
location._add('proxy_set_header', `X-Routing-Rule-Id "${ruleId}"`);
|
|
@@ -428,21 +434,19 @@ class NginxProvider extends BaseProvider {
|
|
|
428
434
|
}
|
|
429
435
|
|
|
430
436
|
// Rewrite path
|
|
431
|
-
|
|
432
|
-
location._add('rewrite', `^${rewritePathPrefix}/?(.*) ${rewrite}$1 break`);
|
|
433
|
-
|
|
437
|
+
location._add('rewrite', `^${rewritePathPrefix}/?(.*) /$1 break`);
|
|
434
438
|
location._add('proxy_pass', `http://127.0.0.1:${process.env.ABT_NODE_SERVICE_PORT}`);
|
|
435
439
|
|
|
436
440
|
return;
|
|
437
441
|
}
|
|
438
442
|
|
|
439
|
-
// Redirect traffic
|
|
440
|
-
|
|
441
|
-
|
|
443
|
+
// Redirect daemon traffic
|
|
444
|
+
const rewritePathPrefix = isDidAuthPath ? DEFAULT_ADMIN_PATH : prefix;
|
|
445
|
+
location._add('proxy_set_header', `X-Path-Prefix "${rewritePathPrefix}"`);
|
|
442
446
|
if (!suffix && prefix !== target) {
|
|
443
447
|
location._add('rewrite', `^${rewritePathPrefix}/?(.*) ${`${target}/`.replace(/\/\//g, '/')}$1 break`);
|
|
444
448
|
}
|
|
445
|
-
|
|
449
|
+
// location._add('rewrite', `^${rewritePathPrefix}/?(.*) /$1 break`);
|
|
446
450
|
location._add('proxy_pass', `http://127.0.0.1:${port}`);
|
|
447
451
|
}
|
|
448
452
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@abtnode/router-provider",
|
|
3
|
-
"version": "1.6.
|
|
3
|
+
"version": "1.6.28",
|
|
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.6.
|
|
36
|
-
"@abtnode/logger": "1.6.
|
|
37
|
-
"@abtnode/router-templates": "1.6.
|
|
38
|
-
"@abtnode/util": "1.6.
|
|
35
|
+
"@abtnode/constant": "1.6.28",
|
|
36
|
+
"@abtnode/logger": "1.6.28",
|
|
37
|
+
"@abtnode/router-templates": "1.6.28",
|
|
38
|
+
"@abtnode/util": "1.6.28",
|
|
39
39
|
"axios": "^0.25.0",
|
|
40
40
|
"debug": "^4.3.3",
|
|
41
41
|
"find-process": "^1.4.3",
|
|
@@ -61,5 +61,5 @@
|
|
|
61
61
|
"fs-extra": "^10.0.0",
|
|
62
62
|
"needle": "^3.0.0"
|
|
63
63
|
},
|
|
64
|
-
"gitHead": "
|
|
64
|
+
"gitHead": "acef8ea339bd8fc9c785312eb5a1a113ecbf0d4d"
|
|
65
65
|
}
|