@abtnode/router-provider 1.7.0 → 1.7.3
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 +29 -19
- package/package.json +6 -6
package/lib/default/daemon.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/* eslint-disable no-continue */
|
|
1
2
|
const url = require('url');
|
|
2
3
|
const path = require('path');
|
|
3
4
|
const fs = require('fs-extra');
|
|
@@ -73,26 +74,27 @@ const createRequestHandler = (id) => (req, res, target) => {
|
|
|
73
74
|
}
|
|
74
75
|
logger.debug('transform url', { url: req.url, rule });
|
|
75
76
|
|
|
77
|
+
// NOTE: x-* header keys must be lower case to avoid collisions from chained proxy
|
|
76
78
|
if (rule.did) {
|
|
77
|
-
req.headers['
|
|
79
|
+
req.headers['x-blocklet-did'] = rule.did;
|
|
78
80
|
}
|
|
79
81
|
if (rule.realDid && rule.did !== rule.realDid) {
|
|
80
|
-
req.headers['
|
|
82
|
+
req.headers['x-blocklet-real-did'] = rule.realDid;
|
|
81
83
|
}
|
|
82
84
|
|
|
83
|
-
req.headers['
|
|
84
|
-
req.headers['
|
|
85
|
+
req.headers['x-path-prefix'] = rule.prefix.replace(WELLKNOWN_SERVICE_PATH_PREFIX, '') || '/';
|
|
86
|
+
req.headers['x-group-path-prefix'] = rule.groupPrefix || '/';
|
|
85
87
|
|
|
86
88
|
if (rule.type === ROUTING_RULE_TYPES.BLOCKLET) {
|
|
87
|
-
req.headers['
|
|
89
|
+
req.headers['x-blocklet-url'] = `http://127.0.0.1:${rule.port}`;
|
|
88
90
|
}
|
|
89
91
|
|
|
90
92
|
if (rule.ruleId) {
|
|
91
|
-
req.headers['
|
|
93
|
+
req.headers['x-routing-rule-id'] = rule.ruleId;
|
|
92
94
|
}
|
|
93
95
|
|
|
94
96
|
if (rule.target && rule.target !== '/') {
|
|
95
|
-
req.headers['
|
|
97
|
+
req.headers['x-routing-rule-path-prefix'] = rule.target;
|
|
96
98
|
}
|
|
97
99
|
};
|
|
98
100
|
|
|
@@ -243,18 +245,23 @@ const updateConfig = (reload = false) => {
|
|
|
243
245
|
|
|
244
246
|
const addedDomains = newDomains.filter((x) => !oldDomains.includes(x));
|
|
245
247
|
for (const domain of addedDomains) {
|
|
246
|
-
if (isSpecificDomain(domain)) {
|
|
247
|
-
|
|
248
|
-
const site = sites.find((x) => x.domain === domain);
|
|
249
|
-
const [rule] = site.rules.filter((x) => ['daemon', 'blocklet'].includes(x.type));
|
|
250
|
-
const match = findCertificate(config.certs, site.domain);
|
|
251
|
-
main.register({
|
|
252
|
-
src: site.domain,
|
|
253
|
-
target: `http://127.0.0.1:${rule.port}`,
|
|
254
|
-
ssl: match ? { key: match.privateKey, cert: match.certificate } : null,
|
|
255
|
-
onRequest: createRequestHandler(rule.id),
|
|
256
|
-
});
|
|
248
|
+
if (isSpecificDomain(domain) === false) {
|
|
249
|
+
continue;
|
|
257
250
|
}
|
|
251
|
+
const site = sites.find((x) => x.domain === domain);
|
|
252
|
+
const [rule] = site.rules.filter((x) => ['daemon', 'blocklet'].includes(x.type));
|
|
253
|
+
if (!rule) {
|
|
254
|
+
continue;
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
logger.info('register domain on reload', { domain });
|
|
258
|
+
const match = findCertificate(config.certs, site.domain);
|
|
259
|
+
main.register({
|
|
260
|
+
src: site.domain,
|
|
261
|
+
target: `http://127.0.0.1:${rule.port}`,
|
|
262
|
+
ssl: match ? { key: match.privateKey, cert: match.certificate } : null,
|
|
263
|
+
onRequest: createRequestHandler(rule.id),
|
|
264
|
+
});
|
|
258
265
|
}
|
|
259
266
|
|
|
260
267
|
const removedDomains = oldDomains.filter((x) => !newDomains.includes(x));
|
|
@@ -304,8 +311,11 @@ config.sites.forEach((site) => {
|
|
|
304
311
|
}
|
|
305
312
|
|
|
306
313
|
const [rule] = site.rules.filter((x) => ['daemon', 'blocklet'].includes(x.type));
|
|
307
|
-
|
|
314
|
+
if (!rule) {
|
|
315
|
+
return;
|
|
316
|
+
}
|
|
308
317
|
|
|
318
|
+
const match = findCertificate(config.certs, domain);
|
|
309
319
|
logger.info('register domain on start', { domain });
|
|
310
320
|
main.register({
|
|
311
321
|
src: domain,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@abtnode/router-provider",
|
|
3
|
-
"version": "1.7.
|
|
3
|
+
"version": "1.7.3",
|
|
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.
|
|
36
|
-
"@abtnode/logger": "1.7.
|
|
37
|
-
"@abtnode/router-templates": "1.7.
|
|
38
|
-
"@abtnode/util": "1.7.
|
|
35
|
+
"@abtnode/constant": "1.7.3",
|
|
36
|
+
"@abtnode/logger": "1.7.3",
|
|
37
|
+
"@abtnode/router-templates": "1.7.3",
|
|
38
|
+
"@abtnode/util": "1.7.3",
|
|
39
39
|
"axios": "^0.25.0",
|
|
40
40
|
"debug": "^4.3.3",
|
|
41
41
|
"find-process": "^1.4.3",
|
|
@@ -62,5 +62,5 @@
|
|
|
62
62
|
"fs-extra": "^10.0.0",
|
|
63
63
|
"needle": "^3.0.0"
|
|
64
64
|
},
|
|
65
|
-
"gitHead": "
|
|
65
|
+
"gitHead": "2b965b42a59a2d98642018749a6afb6e4014a698"
|
|
66
66
|
}
|