@blocklet/crawler 2.1.233 → 2.1.234
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.
|
@@ -63,6 +63,7 @@ Object.keys(_config).forEach(function (key) {
|
|
|
63
63
|
});
|
|
64
64
|
var _util = require("util");
|
|
65
65
|
var _child_process = require("child_process");
|
|
66
|
+
var _component = require("@blocklet/sdk/lib/component");
|
|
66
67
|
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
67
68
|
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
68
69
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
@@ -349,6 +350,19 @@ async function detectBestRedisUrl() {
|
|
|
349
350
|
const possibleUrls = [
|
|
350
351
|
// environment variable priority
|
|
351
352
|
process.env.REDIS_URL,
|
|
353
|
+
// by web component endpoint
|
|
354
|
+
(() => {
|
|
355
|
+
try {
|
|
356
|
+
const endpoint = (0, _component.getComponentWebEndpoint)(_config.default.env.componentDid);
|
|
357
|
+
if (endpoint) {
|
|
358
|
+
const url = new URL(endpoint);
|
|
359
|
+
return `redis://${url.hostname}:6379`;
|
|
360
|
+
}
|
|
361
|
+
} catch (err) {
|
|
362
|
+
logger.warn(`Failed to get component endpoint: ${err.message}`);
|
|
363
|
+
}
|
|
364
|
+
return null;
|
|
365
|
+
})(),
|
|
352
366
|
// default gateway
|
|
353
367
|
defaultGateway ? `redis://${defaultGateway}:6379` : null,
|
|
354
368
|
// common Docker gateway
|
|
@@ -365,7 +379,7 @@ async function detectBestRedisUrl() {
|
|
|
365
379
|
});
|
|
366
380
|
testClient.on("error", () => {});
|
|
367
381
|
await Promise.race([testClient.connect(), new Promise((_, reject) => setTimeout(() => reject(new Error("Connection timeout")), 2e3))]);
|
|
368
|
-
|
|
382
|
+
await testClient.ping();
|
|
369
383
|
await testClient.disconnect();
|
|
370
384
|
logger.info(`\u2705 Found available Redis connection: ${url}`);
|
|
371
385
|
cachedRedisUrl = url;
|
|
@@ -13,6 +13,7 @@ import uniq from "lodash/uniq";
|
|
|
13
13
|
import config from "@blocklet/sdk/lib/config";
|
|
14
14
|
import { promisify } from "util";
|
|
15
15
|
import { exec } from "child_process";
|
|
16
|
+
import { getComponentWebEndpoint } from "@blocklet/sdk/lib/component";
|
|
16
17
|
export * from "@blocklet/sdk/lib/config";
|
|
17
18
|
const { logger } = config;
|
|
18
19
|
const execAsync = promisify(exec);
|
|
@@ -374,6 +375,19 @@ async function detectBestRedisUrl() {
|
|
|
374
375
|
const possibleUrls = [
|
|
375
376
|
// environment variable priority
|
|
376
377
|
process.env.REDIS_URL,
|
|
378
|
+
// by web component endpoint
|
|
379
|
+
(() => {
|
|
380
|
+
try {
|
|
381
|
+
const endpoint = getComponentWebEndpoint(config.env.componentDid);
|
|
382
|
+
if (endpoint) {
|
|
383
|
+
const url = new URL(endpoint);
|
|
384
|
+
return `redis://${url.hostname}:6379`;
|
|
385
|
+
}
|
|
386
|
+
} catch (err) {
|
|
387
|
+
logger.warn(`Failed to get component endpoint: ${err.message}`);
|
|
388
|
+
}
|
|
389
|
+
return null;
|
|
390
|
+
})(),
|
|
377
391
|
// default gateway
|
|
378
392
|
defaultGateway ? `redis://${defaultGateway}:6379` : null,
|
|
379
393
|
// common Docker gateway
|
|
@@ -393,7 +407,7 @@ async function detectBestRedisUrl() {
|
|
|
393
407
|
testClient.connect(),
|
|
394
408
|
new Promise((_, reject) => setTimeout(() => reject(new Error("Connection timeout")), 2e3))
|
|
395
409
|
]);
|
|
396
|
-
|
|
410
|
+
await testClient.ping();
|
|
397
411
|
await testClient.disconnect();
|
|
398
412
|
logger.info(`\u2705 Found available Redis connection: ${url}`);
|
|
399
413
|
cachedRedisUrl = url;
|