Files
opro_demo/.trae/documents/修复预览访问与静态页面挂载.md
2025-12-05 07:11:25 +00:00

37 lines
2.1 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

## 问题分析
- 浏览器报错 `net::ERR_ABORTED http://0.0.0.0:8010/`,常见于预览环境对 `0.0.0.0` 的访问被中止或跳转流程未完成。
- 现有后端已启动并挂载静态目录到 `/`,但预览器可能对根路径加载敏感,或端口/主机解析不一致。
- 目前 API 路由与静态挂载并存,使用相对 `fetch('/query')` 正常;问题主要是根页面加载。
## 修复方案
1. 主机与端口访问
- 推荐使用 `http://127.0.0.1:8010/``http://localhost:8010/` 访问,而不是 `0.0.0.0`
- 新增 `/health` 路由用于快速诊断服务是否运行。
2. 静态页面挂载位置
- 将静态目录从根 `/` 改为 `/ui` 挂载,降低与根路径的潜在冲突。
- 新增 `GET /` 路由,返回 `frontend/index.html` 或 302 跳转到 `/ui/index.html`
3. 前端请求与错误处理
- 保持相对路径 `fetch('/query')``/select``/reject`,保持同源;增强错误提示(显示响应状态与内容)。
- 若需要跨源(前端单独部署),补充 CORS允许前端源访问后端 API。
4. 诊断与验证
- 使用 `curl http://127.0.0.1:8010/health` 验证健康。
- 使用 `curl` 端到端:`/query`(新会话与带 `session_id` 再生)、`/select`(生成答案)。
- 浏览器打开 `/ui/` 页面,执行完整流程:开始生成 → 拒绝并再生 → 选择并出答案。
## 具体改动清单
- `_qwen_xinference_demo/api.py`
- 添加 `GET /health` 路由返回 `{status:"ok"}`
-`StaticFiles(directory="frontend", html=True)``/` 挂载到 `/ui`
- 添加 `GET /` 路由,返回 `index.html` 或重定向到 `/ui/index.html`
- `frontend/index.html`
- 增强错误显示:同时显示响应状态码与文本(提升诊断能力)。
## 后续增强(可选)
-`/query``/select` 增加耗时、来源日志,便于问题排查。
- 在页面上展示历史候选与拒绝原因列表,提升可观测性。
- 提供配置项切换嵌入优先级Xinference/Ollama
请确认是否按以上方案进行修改与验证,我将立即实施并完成端到端测试。