refactor: 移除自签名证书方案,服务只跑 HTTP
麦克风安全上下文改由部署方案解决:本机用 localhost, 对外部署挂 HTTPS 反向代理。删除 certs/、gen-cert.sh、 /cert 路由与 HTTPS server 分支,文档同步更新。 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
26
server.js
26
server.js
@@ -8,7 +8,6 @@
|
||||
* 模型:./models/ggml-small.bin(默认,较准)或 ggml-base.bin(较快,用 WHISPER_MODEL 切换)
|
||||
*/
|
||||
const http = require('http');
|
||||
const https = require('https');
|
||||
const fs = require('fs');
|
||||
const os = require('os');
|
||||
const path = require('path');
|
||||
@@ -17,7 +16,6 @@ const crypto = require('crypto');
|
||||
|
||||
const ROOT = __dirname;
|
||||
const PORT = process.env.PORT || 8000;
|
||||
const HTTPS_PORT = process.env.HTTPS_PORT || 8443;
|
||||
const THREADS = String(Math.min(8, os.cpus().length || 4));
|
||||
const WHISPER = process.env.WHISPER_BIN || 'whisper-cli';
|
||||
const FFMPEG = process.env.FFMPEG_BIN || 'ffmpeg';
|
||||
@@ -126,15 +124,6 @@ function handler(req, res) {
|
||||
});
|
||||
return;
|
||||
}
|
||||
// ---- iOS 下载证书(浏览器打开会提示安装描述文件) ----
|
||||
if (req.method === 'GET' && url.pathname === '/cert') {
|
||||
fs.readFile(path.join(ROOT, 'certs', 'calx-cert.cer'), (e, data) => {
|
||||
if (e) { res.writeHead(404); res.end('cert not found'); return; }
|
||||
res.writeHead(200, { 'Content-Type': 'application/x-x509-ca-cert', 'Content-Disposition': 'attachment; filename="calx-cert.cer"' });
|
||||
res.end(data);
|
||||
});
|
||||
return;
|
||||
}
|
||||
if (req.method === 'GET' && url.pathname === '/health') {
|
||||
res.writeHead(200, { 'Content-Type': 'application/json' });
|
||||
res.end(JSON.stringify({ ok: true, model: path.basename(MODEL), modelExists: fs.existsSync(MODEL) }));
|
||||
@@ -170,18 +159,5 @@ http.createServer(handler).listen(PORT, '0.0.0.0', () => {
|
||||
console.log(`\n乘法口诀服务已启动`);
|
||||
console.log(` HTTP : http://localhost:${PORT} http://${IP}:${PORT}`);
|
||||
console.log(`识别引擎: ${WHISPER} 模型: ${path.basename(MODEL)} ${fs.existsSync(MODEL) ? '✅' : '❌ 模型不存在'} 线程: ${THREADS} 语法约束: ${HAS_GRAMMAR ? '✅' : '❌(用prompt)'}`);
|
||||
console.log(`提示: 浏览器麦克风需要安全上下文——本机用 http://localhost:${PORT};对外部署请挂在支持 HTTPS 的反向代理后面`);
|
||||
});
|
||||
|
||||
// ---- HTTPS(iOS 用麦克风必需)----
|
||||
try {
|
||||
const key = path.join(ROOT, 'certs', 'key.pem');
|
||||
const cert = path.join(ROOT, 'certs', 'cert.pem');
|
||||
if (fs.existsSync(key) && fs.existsSync(cert)) {
|
||||
https.createServer({ key: fs.readFileSync(key), cert: fs.readFileSync(cert) }, handler)
|
||||
.listen(HTTPS_PORT, '0.0.0.0', () => {
|
||||
console.log(` HTTPS: https://${IP}:${HTTPS_PORT} (iOS 用这个,先访问 https://${IP}:${HTTPS_PORT}/cert 安装并信任证书)`);
|
||||
});
|
||||
} else {
|
||||
console.log(' HTTPS: 未启用(缺少 certs/key.pem 或 certs/cert.pem)');
|
||||
}
|
||||
} catch (e) { console.log(' HTTPS 启动失败:', e.message); }
|
||||
|
||||
Reference in New Issue
Block a user