Repository navigation
refactor(http): 合并三处重复的 HTTP 封装为统一 fetch 客户端 - #2
Merged
Merged
Conversation
added 3 commits
September 28, 2026 02:41
auth.js / models.js / cli-login.js 各自拷贝了一份 https.request 封装(代理、 超时、JSON 解析),proxy.js 另有一套。现合并为 src/http.js:基于 undici 的 fetch,按需注入代理 dispatcher,提供 request()(读完响应体)与 rawFetch() (保留响应流,用于 SSE 转发)。依赖 https-proxy-agent 换成 undici。 验证:node:22-alpine 下 npm install 后运行 test.js,覆盖普通请求 / 404 / 超时 / 无代理 dispatcher / 首页与 /health、/status、/fast,以及 /v1/responses 的 SSE 流式转发,全部通过。
新增 test/smoke.js(零依赖断言,失败即非零退出),覆盖 src/http 客户端 (正常/404/超时/无代理)、app 路由(/health、/status、/fast、首页)以及 /v1/responses 的 SSE 流式转发;package.json 增加 test 脚本与 engines。
- ci.yml:pull_request 与 main 推送时跑 npm ci + 语法检查 + npm test。 - release.yml:推 release 分支或 v*.*.* tag 时构建并推送 ghcr.io 镜像, 打 release/latest 与语义化版本 tag,供本地 docker pull。
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.
背景
auth.js/models.js/cli-login.js各自拷贝了一份https.request封装(代理、超时、JSON 解析),proxy.js另有一套。四处重复、维护成本高。改动
src/http.js:基于 undici 的fetch,按需注入代理 dispatcher,提供request()(读完响应体)与rawFetch()(保留响应流,用于 SSE)。auth.js/models.js/cli-login.js/proxy.js全部改用该模块;依赖https-proxy-agent→undici。proxy.js用Readable.fromWeb做 SSE 流式转发,重试按cause识别网络错误。CODEX_RESPONSES_URL覆盖,便于本地测试。验证
node:22-alpine下npm ci后运行测试脚本,覆盖:普通请求 / 404 / 超时 / 无代理 dispatcher / 首页与/health、/status、/fast、以及/v1/responses的 SSE 流式转发 → ALL TESTS PASSED。