@make-u-free/migi 0.2.5 → 0.2.6
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/package.json +1 -1
- package/src/tls.js +22 -11
package/package.json
CHANGED
package/src/tls.js
CHANGED
|
@@ -1,19 +1,30 @@
|
|
|
1
|
-
import { existsSync, readFileSync } from 'fs'
|
|
2
|
-
import { join } from 'path'
|
|
1
|
+
import { existsSync, readFileSync, readdirSync } from 'fs'
|
|
2
|
+
import { join, extname } from 'path'
|
|
3
3
|
import { homedir } from 'os'
|
|
4
4
|
import https from 'https'
|
|
5
5
|
import tls from 'tls'
|
|
6
6
|
|
|
7
|
-
//
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
7
|
+
// .migi/ ディレクトリ内の .crt / .pem を名前不問でスキャン
|
|
8
|
+
function scanDir(dir) {
|
|
9
|
+
if (!existsSync(dir)) return []
|
|
10
|
+
try {
|
|
11
|
+
return readdirSync(dir)
|
|
12
|
+
.filter(f => ['.crt', '.pem'].includes(extname(f).toLowerCase()))
|
|
13
|
+
.map(f => join(dir, f))
|
|
14
|
+
} catch {
|
|
15
|
+
return []
|
|
16
|
+
}
|
|
17
|
+
}
|
|
14
18
|
|
|
15
19
|
function findCA() {
|
|
16
|
-
|
|
20
|
+
// 優先順: 環境変数 → カレント.migi/ → ホーム.migi/
|
|
21
|
+
const candidates = [
|
|
22
|
+
process.env.NODE_EXTRA_CA_CERTS,
|
|
23
|
+
...scanDir(join(process.cwd(), '.migi')),
|
|
24
|
+
...scanDir(join(homedir(), '.migi')),
|
|
25
|
+
].filter(Boolean)
|
|
26
|
+
|
|
27
|
+
for (const p of candidates) {
|
|
17
28
|
if (existsSync(p)) return p
|
|
18
29
|
}
|
|
19
30
|
return null
|
|
@@ -47,7 +58,7 @@ if (caPath) {
|
|
|
47
58
|
|
|
48
59
|
console.log(` [TLS] CA loaded: ${caPath}`)
|
|
49
60
|
} else {
|
|
50
|
-
console.log(' [TLS] CA未設定 (社内エラー時は
|
|
61
|
+
console.log(' [TLS] CA未設定 (社内エラー時は .migi/ に .crt/.pem を配置)')
|
|
51
62
|
}
|
|
52
63
|
|
|
53
64
|
export const httpsAgent = _httpsAgent
|