fix: webui在使用反向代理时url无法正确处理#257
Open
kakaa-nju wants to merge 2 commits into
Open
Conversation
Contributor
There was a problem hiding this comment.
Hey - 我在这里给出了一些整体性的反馈:
- 在
getWsUrl和getApiBase中新增的window.location.host检查几乎总是会提前返回,从而实际忽略了在非代理或开发/Tauri 场景下的serverPort/backendPort回退逻辑;建议不要简单依赖window.location.host,而是用更明确的条件来决定是否启用“代理模式”行为。 - 像
getWsUrl和getApiBase中硬编码的回退端口12701,可能会与真实配置不一致;更安全的做法是从现有的配置或状态派生这些值,而不是在此直接写死常量。
给 AI Agents 的提示
请根据这次代码审查中的评论进行修改:
## 整体点评
- 在 `getWsUrl` 和 `getApiBase` 中新增的 `window.location.host` 检查几乎总是会提前返回,从而实际忽略了在非代理或开发/Tauri 场景下的 `serverPort`/`backendPort` 回退逻辑;建议不要简单依赖 `window.location.host`,而是用更明确的条件来决定是否启用“代理模式”行为。
- 像 `getWsUrl` 和 `getApiBase` 中硬编码的回退端口 `12701`,可能会与真实配置不一致;更安全的做法是从现有的配置或状态派生这些值,而不是在此直接写死常量。帮我变得更有用!请在每条评论上点 👍 或 👎,我会根据你的反馈改进后续的代码审查。
Original comment in English
Hey - I've left some high level feedback:
- The new
window.location.hostchecks ingetWsUrlandgetApiBasewill almost always short‑circuit the fallback branches, effectively ignoringserverPort/backendPortin non‑proxy or dev/Tauri scenarios; consider gating the proxy-style behavior on a more explicit condition instead ofwindow.location.host. - Hardcoded fallback ports like
12701ingetWsUrlandgetApiBasemay diverge from actual configuration; it would be safer to derive these values from existing config/state rather than embedding constants here.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The new `window.location.host` checks in `getWsUrl` and `getApiBase` will almost always short‑circuit the fallback branches, effectively ignoring `serverPort`/`backendPort` in non‑proxy or dev/Tauri scenarios; consider gating the proxy-style behavior on a more explicit condition instead of `window.location.host`.
- Hardcoded fallback ports like `12701` in `getWsUrl` and `getApiBase` may diverge from actual configuration; it would be safer to derive these values from existing config/state rather than embedding constants here.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
Contributor
Author
在 WebUI 场景下,window.location.host 始终指向用户实际访问的地址,无论是通过代理还是直连,都是正确的服务端地址。 当前回退 host 和 port 均先从配置中读取,如果未设置才会回退到硬编码
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
bug触发条件:
结果:wss 和 /api/* 的连接会请求 “maaend.example.icu:12701/{uri}”
本 pr 使用
window.location.host获取正确的 url,并在失败时 fallback 到原本的逻辑Sourcery 总结
修复 Web UI 中的 URL 处理问题,使在通过反向代理访问时 WebSocket 和 API 请求能够正常工作,并在直接连接后端时提供合理的回退机制。
Bug 修复:
window.location.host和origin来解析 WebSocket 和 API 端点 URL,解决端点 URL 不正确的问题。Original summary in English
Summary by Sourcery
Fix URL handling in the web UI so that WebSocket and API requests work correctly when accessed via a reverse proxy, with sensible fallbacks for direct backend connections.
Bug Fixes: