dsh-qwenwork-connect 0.2.0 → 0.2.2
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/loopback.js +18 -3
- package/package.json +1 -1
package/lib/loopback.js
CHANGED
|
@@ -8,16 +8,31 @@
|
|
|
8
8
|
* @module dsh-qwenwork-connect/loopback
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
|
+
import fs from 'node:fs';
|
|
12
|
+
import os from 'node:os';
|
|
13
|
+
import path from 'node:path';
|
|
14
|
+
|
|
11
15
|
/** 本地插件面可被寻址的环回主机名。 */
|
|
12
16
|
/**
|
|
13
17
|
* 额外信任的 Host(逗号分隔)。DSH 常通过 dsh.lan 之类的反代域名访问,
|
|
14
18
|
* 那时 Host 不是环回但请求仍来自本机代理;部署时用这个环境变量补齐。
|
|
15
19
|
*/
|
|
16
20
|
function extraTrustedHosts() {
|
|
17
|
-
const
|
|
21
|
+
const parts = [];
|
|
22
|
+
const fromEnv = process.env.QWENWORK_TRUSTED_HOSTS;
|
|
23
|
+
if (typeof fromEnv === 'string' && fromEnv.length > 0) parts.push(fromEnv);
|
|
24
|
+
// DSH 往往由 systemd 托管,进程环境改不了;用文件更实际:
|
|
25
|
+
// ~/.dsh/qwenwork-trusted-hosts,一行一个域名(也接受逗号分隔)。
|
|
26
|
+
try {
|
|
27
|
+
const file = path.join(os.homedir(), '.dsh', 'qwenwork-trusted-hosts');
|
|
28
|
+
parts.push(fs.readFileSync(file, 'utf8'));
|
|
29
|
+
} catch {
|
|
30
|
+
// 没有这个文件就是不需要额外放行
|
|
31
|
+
}
|
|
18
32
|
return new Set(
|
|
19
|
-
|
|
20
|
-
.
|
|
33
|
+
parts
|
|
34
|
+
.join(',')
|
|
35
|
+
.split(/[\s,]+/)
|
|
21
36
|
.map((item) => item.trim().toLowerCase())
|
|
22
37
|
.filter((item) => item.length > 0),
|
|
23
38
|
);
|