Files
memind/scripts/local-test-tls.mjs
T
john 54de1dd8e3 Add local test domain setup (test.*.tkmind.cn).
DNS/TLS/proxy scripts and docs/local-dev.md replace localhost URLs for H5, memind_adm, Plaza, and Ops during local dev.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-17 09:55:04 +08:00

39 lines
1.3 KiB
JavaScript

#!/usr/bin/env node
import fs from 'node:fs';
import path from 'node:path';
import { execSync } from 'node:child_process';
import { fileURLToPath } from 'node:url';
import { H5_HOST, TEST_HOSTS } from './local-test-config.mjs';
const root = path.join(path.dirname(fileURLToPath(import.meta.url)), '..');
const certDir = path.join(root, '.local/local-test-tls');
const keyPath = path.join(certDir, 'local-test.key.pem');
const certPath = path.join(certDir, 'local-test.cert.pem');
export function ensureLocalTestTls() {
if (fs.existsSync(keyPath) && fs.existsSync(certPath)) {
return { keyPath, certPath, certDir };
}
fs.mkdirSync(certDir, { recursive: true });
const sans = [
...TEST_HOSTS.map((host) => `DNS:${host}`),
'DNS:localhost',
'IP:127.0.0.1',
].join(',');
const openssl = `openssl req -x509 -newkey rsa:2048 -sha256 -days 825 -nodes \
-keyout "${keyPath}" -out "${certPath}" \
-subj "/CN=${H5_HOST}" \
-addext "subjectAltName=${sans}"`;
execSync(openssl, { stdio: 'inherit' });
console.log(`已生成本地 TLS 证书:${certDir}`);
console.log(`SAN: ${TEST_HOSTS.join(', ')}`);
console.log('浏览器首次访问需信任该自签证书。');
return { keyPath, certPath, certDir };
}
if (process.argv[1] && path.resolve(process.argv[1]) === fileURLToPath(import.meta.url)) {
ensureLocalTestTls();
}