feat: 添加HTTP接口支持Postman测试

- 添加 tiny_http 依赖用于HTTP服务器
- 守护进程自动启动HTTP服务器(端口=TCP端口+1)
- 添加 /synthesize 接口(POST)
- 添加 /health 健康检查接口(GET)
- 测试通过: curl 和 mimo-tts send 命令
This commit is contained in:
2026-04-25 06:34:54 +08:00
parent 19eb313bef
commit 96b3aa4a37
5 changed files with 171 additions and 0 deletions

View File

@@ -475,6 +475,46 @@
- `WARN` - 包含"警告"、"注意"
- `ERROR` - 包含"错误"、"失败"、"无法"
---
## 2026-04-25 - 第十三轮:添加 HTTP 接口
### 用户需求
让 Postman 可以测试守护进程:
- 添加 HTTP 接口(端口 9877
- 支持 POST /synthesize 接口
- 支持 GET /health 健康检查
### 实施完成
1. ✅ 添加 tiny_http 依赖
2. ✅ 在 daemon.rs 添加 HTTP 服务器函数
3. ✅ 自动启动 HTTP 服务器(端口 = TCP端口 + 1
4. ✅ 测试通过:
- `curl http://127.0.0.1:9877/synthesize`
- `curl http://127.0.0.1:9877/health`
### HTTP 接口设计
| 地址 | 方法 | 说明 |
|------|------|------|
| `http://127.0.0.1:9877/synthesize` | POST | 语音合成 |
| `http://127.0.0.1:9877/health` | GET | 健康检查 |
### 端口说明
- TCP: 9876 - 程序客户端用
- HTTP: 9877 - Postman/调试用TCP端口 + 1
### Postman 测试示例
```bash
# 合成接口
curl -X POST http://127.0.0.1:9877/synthesize \
-H "Content-Type: application/json" \
-d '{"text":"你好世界"}'
# 健康检查
curl http://127.0.0.1:9877/health
```
### 踩坑记录
1. **clap 参数传递问题**
- 问题:`--port` 参数无法传递给 `daemon start` 子命令