Skip to content

fix(tunnel): 修复公开地址端口与动态资源路径 - #809

Open
yovinchen wants to merge 1 commit into
Stack-Cairn:mainfrom
yovinchen:fix/tunnel-public-url-and-dynamic-assets
Open

yovinchen wants to merge 1 commit into
Stack-Cairn:mainfrom
yovinchen:fix/tunnel-public-url-and-dynamic-assets

Conversation

@yovinchen

@yovinchen yovinchen commented Sep 13, 2026

Copy link
Copy Markdown
Contributor

Linked issue

Closes #807
Closes #808

Summary

修复 HTTP 隧道的两个路径问题:Desktop 单独配置 Gateway 端口时,面板和 TunnelManager 输出会丢失端口;页面动态插入 script/link 时,原生资源加载器会请求 Gateway 根路径并返回 404。

统一从 gatewayUrlgatewayPort 生成公开基址,使 http://127.0.0.1 + 3000 正确生成 http://127.0.0.1:3000/t/<slug>/。隧道运行时在原生 URL 属性赋值、属性设置和节点插入前同步处理动态 script/link 路径,同时保留外部来源、相对地址和已带前缀的资源。

运行时从 Go 字符串提取为嵌入的 JavaScript,HTML 注入和 CSP 哈希仍使用同一份字节。没有新增依赖或修改协议。

Change scope

  • Modules: agent-gui、agent-ui、agent-gateway。
  • Key paths: ChatPage.tsxuseSendChatTurn.tsRemoteSection.tsxgatewayPublicUrl.tsinternal/server/tunnel_rewrite.gotunnel_runtime.js
  • 补充公开 URL、工具输出、动态脚本/样式及不同 DOM 插入方式的回归测试,并更新 Gateway 架构说明。

Screenshots / preview

下面是真实 Chromium 浏览器中的最小复现页面截图,不是产品界面截图。左侧使用 main@4eb6a4a8 的原版运行时,右侧使用本 PR 的嵌入运行时;端口行执行对应的基址生成逻辑。

公开链接和动态资源的修复前后对照

公开地址(修复前) http://127.0.0.1/t/example/
公开地址(修复后) http://127.0.0.1:3000/t/example/

动态 script.src = '/lazy-root.js'
修复前 GET /lazy-root.js                -> 404,脚本未执行
修复后 GET /t/after/lazy-root.js        -> 200,脚本执行成功

另外在本地 Docker Gateway + Desktop 的真实隧道上复测,原复现页由 8/9 通过变为 9/9 通过(包含动态脚本与按钮交互)。

Verification

  • make check-all 完整通过:21/21 检查项 PASS,包含 Shared UI 边界与类型检查、GUI/WebUI 构建和 lint、Go lint 与全部 Go 测试、前端/发布脚本测试、Rust 全目标与 doc tests、Proto lint 和 breaking check。macOS arm64 上使用独立临时目录,排除其他 golangci-lint 进程锁冲突;需要进程查询和日志写入的 Rust 测试在正常权限下执行,1003 项通过、3 项原有忽略。

  • 21 项针对性 Node 回归测试通过,覆盖端口归一化、TunnelManager 输出、动态 script/link、克隆和片段插入、已带前缀及外部资源保持、fetch/XHR 回归。

  • Chromium 前后对照验证通过,截图见上。

  • git diff --check 通过。

兼容范围:本次修复限定为公开基址和动态 DOM script/link 资源。原生 ES module 根路径导入、Worker、客户端路由和动态 HTML 字符串仍可能需要应用自身的 basePath 适配,文档已明确说明。

Pre-submit checklist

  • A requirement issue is linked.
  • Synced with the target branch; no merge conflicts.
  • The change is focused, with no unrelated modifications.
  • No secrets, tokens, or personal data included.
  • Docs are updated for changes affecting user behavior, deployment, or configuration.

@yovinchen
yovinchen marked this pull request as ready for review September 13, 2026 16:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] HTTP 隧道动态 script/link 资源绕过路径改写并返回 404 [Bug] Desktop 隧道公开链接丢失独立配置的 Gateway 端口

1 participant