Skip to content

fix: support split web/api domains in usage-doc examples#982

Merged
ding113 merged 4 commits into
ding113:devfrom
xuesongjun:fix/usage-doc-split-domain
Apr 14, 2026
Merged

fix: support split web/api domains in usage-doc examples#982
ding113 merged 4 commits into
ding113:devfrom
xuesongjun:fix/usage-doc-split-domain

Conversation

@xuesongjun

@xuesongjun xuesongjun commented Mar 29, 2026

Copy link
Copy Markdown
Contributor

Summary

This PR fixes generated client configuration examples on the usage-doc page for deployments where the Web UI domain and API domain are separated.

Previously, the page used the current site origin (window.location.origin) for all client examples. This works for single-domain deployments, but fails for
split-domain setups such as:

  • Web UI: https://example.com
  • API: https://api.example.com

In that case, users open the docs page on the Web domain, but the generated CLI/SDK examples incorrectly show the Web domain instead of the actual API domain.

Changes

  • Added an API-specific origin for client examples:
    • prefer NEXT_PUBLIC_API_BASE_URL environment variable
    • fallback to the current site origin for backward compatibility
  • Updated usage-doc examples to use the API origin for client-facing configurations:
    • Claude Code (settings.json, environment variables, verification output)
    • Codex (config.toml with both auth.json and env-var methods)
    • Gemini CLI (.env file and environment variables)
    • OpenCode (opencode.json with cchClaude, cchGPT, cchGemini providers)
    • Droid (config.json custom models)
    • Updated the Unix network test example to use /v1/messages instead of the root URL, providing a more accurate connectivity test for API-only subdomains (returns 401 Unauthorized when reachable but unauthenticated, rather than misleading 403 from blocked root paths)

Why

This improves documentation correctness for reverse-proxy and split-domain deployments (control plane / data plane separation) without breaking existing
single-domain setups.

If NEXT_PUBLIC_API_BASE_URL is not configured, the previous behavior is preserved.

Compatibility

  • No breaking change for existing single-domain deployments
  • Split-domain deployments can now display correct API endpoints in generated examples by setting NEXT_PUBLIC_API_BASE_URL=https://api.example.com

Greptile Summary

This PR introduces apiOrigin — computed from a new NEXT_PUBLIC_API_BASE_URL env var with a fallback to the current site origin — and applies it across all generated client-configuration examples on the usage-doc page, fixing split-domain (Web UI vs. API) deployments.

  • The apiOrigin derivation and trailing-slash sanitization are correct; all code-block examples are updated.
  • Three inline i18n template substitutions (lines 1169, 1269, 1762) still inject resolvedOrigin instead of apiOrigin. The translation strings at those points contain API endpoint URL guidance, so in a split-domain setup the adjacent instructional text would contradict the code blocks shown above them.

Confidence Score: 4/5

Safe to merge after fixing three inline i18n substitutions that still inject the Web UI origin into API-URL instructional text.

One P1 finding: the PR's primary goal (correct API origin in docs for split-domain setups) is partially unmet because three .replace() calls still pass resolvedOrigin instead of apiOrigin, making the instructional notes inconsistent with the code blocks they annotate. All other changes are correct.

src/app/[locale]/usage-doc/page.tsx lines 1169, 1269, and 1762

Important Files Changed

Filename Overview
src/app/[locale]/usage-doc/page.tsx Adds apiOrigin from NEXT_PUBLIC_API_BASE_URL and correctly updates all code-block examples, but misses three inline i18n template substitutions (lines 1169, 1269, 1762) that still inject the Web UI origin into API-URL instructional text.
.env.example Adds commented-out NEXT_PUBLIC_API_BASE_URL with clear documentation for split-domain deployments; no issues.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[UsageDocContent renders] --> B{NEXT_PUBLIC_API_BASE_URL set at build time?}
    B -->|Yes| C[trim + strip trailing slash]
    B -->|No| D[result is empty string]
    C --> E{Non-empty after sanitize?}
    E -->|Yes| F[apiOrigin = env var value]
    E -->|No| D
    D --> G[apiOrigin = resolvedOrigin\nwindow.location.origin]
    F --> H[Code blocks use apiOrigin]
    G --> H
    H --> I[Correct for split-domain]
    H --> J[i18n text substitutions\nlines 1169 / 1269 / 1762\nstill use resolvedOrigin]
    J --> K[Mismatch in split-domain:\ntext shows Web UI domain\ncode shows API domain]
    style K fill:#f99,stroke:#c00
Loading

Comments Outside Diff (2)

  1. src/app/[locale]/usage-doc/page.tsx, line 1510 (link)

    P1 Windows network test still uses resolvedOrigin instead of apiOrigin

    This line was not updated as part of the PR, so in a split-domain deployment (the exact scenario this PR targets), the Windows connectivity test will probe the web UI domain rather than the API domain. A user following the troubleshooting guide on Windows would be testing the wrong host.

    The Unix equivalent on line 1519 was correctly updated to use apiOrigin, so this is an inconsistency introduced by the PR.

    Prompt To Fix With AI
    This is a comment left during a code review.
    Path: src/app/[locale]/usage-doc/page.tsx
    Line: 1510
    
    Comment:
    **Windows network test still uses `resolvedOrigin` instead of `apiOrigin`**
    
    This line was not updated as part of the PR, so in a split-domain deployment (the exact scenario this PR targets), the Windows connectivity test will probe the **web UI domain** rather than the API domain. A user following the troubleshooting guide on Windows would be testing the wrong host.
    
    The Unix equivalent on line 1519 was correctly updated to use `apiOrigin`, so this is an inconsistency introduced by the PR.
    
    
    
    How can I resolve this? If you propose a fix, please make it concise.
  2. src/app/[locale]/usage-doc/page.tsx, line 1169 (link)

    P1 Inline important notes still substitute resolvedOrigin instead of apiOrigin

    Three places in this file replace the i18n placeholder in translation strings with resolvedOrigin (the Web UI origin), while the code blocks immediately above were correctly updated to use apiOrigin. In a split-domain deployment this creates a direct contradiction: the JSON config snippet shows the API domain, but the adjacent "Important" note tells the user to use the Web UI domain for the same setting.

    The same mismatch exists at line 1269 (Droid importantPoints) and line 1762 (troubleshooting endpointConfigError.points) — all three translation strings contain API endpoint URL references such as "Anthropic format: Use ... (no /v1)" and "OpenAI format: Use .../v1".

    The fix for all three occurrences is to change the second argument of .replace(...) from resolvedOrigin to apiOrigin.

    Prompt To Fix With AI
    This is a comment left during a code review.
    Path: src/app/[locale]/usage-doc/page.tsx
    Line: 1169
    
    Comment:
    **Inline important notes still substitute `resolvedOrigin` instead of `apiOrigin`**
    
    Three places in this file replace the i18n placeholder in translation strings with `resolvedOrigin` (the Web UI origin), while the code blocks immediately above were correctly updated to use `apiOrigin`. In a split-domain deployment this creates a direct contradiction: the JSON config snippet shows the API domain, but the adjacent "Important" note tells the user to use the Web UI domain for the same setting.
    
    The same mismatch exists at line 1269 (Droid `importantPoints`) and line 1762 (troubleshooting `endpointConfigError.points`) — all three translation strings contain API endpoint URL references such as `"Anthropic format: Use ... (no /v1)"` and `"OpenAI format: Use .../v1"`.
    
    The fix for all three occurrences is to change the second argument of `.replace(...)` from `resolvedOrigin` to `apiOrigin`.
    
    How can I resolve this? If you propose a fix, please make it concise.
Prompt To Fix All With AI
This is a comment left during a code review.
Path: src/app/[locale]/usage-doc/page.tsx
Line: 1169

Comment:
**Inline important notes still substitute `resolvedOrigin` instead of `apiOrigin`**

Three places in this file replace the i18n placeholder in translation strings with `resolvedOrigin` (the Web UI origin), while the code blocks immediately above were correctly updated to use `apiOrigin`. In a split-domain deployment this creates a direct contradiction: the JSON config snippet shows the API domain, but the adjacent "Important" note tells the user to use the Web UI domain for the same setting.

The same mismatch exists at line 1269 (Droid `importantPoints`) and line 1762 (troubleshooting `endpointConfigError.points`) — all three translation strings contain API endpoint URL references such as `"Anthropic format: Use ... (no /v1)"` and `"OpenAI format: Use .../v1"`.

The fix for all three occurrences is to change the second argument of `.replace(...)` from `resolvedOrigin` to `apiOrigin`.

How can I resolve this? If you propose a fix, please make it concise.

Reviews (3): Last reviewed commit: "Merge branch 'dev' into fix/usage-doc-sp..." | Re-trigger Greptile

@coderabbitai

coderabbitai Bot commented Mar 29, 2026

Copy link
Copy Markdown
📝 Walkthrough

Walkthrough

将 UsageDocContent 修改为从 process.env.NEXT_PUBLIC_API_BASE_URL(去除尾部斜杠、空白)计算 apiOrigin,以 resolvedOrigin 作为后备;在生成的文档/代码示例中将对 resolvedOrigin 的引用替换为 apiOrigin。另在 .env.example 中添加了该环境变量的注释示例。

Changes

Cohort / File(s) Summary
Usage 文档与示例代码
src/app/[locale]/usage-doc/page.tsx
将示例配置/代码片段中所有对 resolvedOrigin 的引用替换为派生自 NEXT_PUBLIC_API_BASE_URLapiOrigin(去除尾部 /),包括 Claude Code、Codex、OpenCode(@ai-sdk)、Gemini、Droid 自定义模型及 OpenCode 的 cch 模型条目;更新故障排查命令(Windows 测试主机改为 apiOrigin,Unix curl 指向 ${apiOrigin}/v1/messages)。
示例环境变量
.env.example
新增注释示例 NEXT_PUBLIC_API_BASE_URL 配置块及说明,指导在前端与 API 分离部署时设置该值;保留为空时默认使用站点域名。

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed 标题准确概括了拉取请求的主要变更,即支持在分离的Web/API域部署中生成正确的使用文档示例。
Description check ✅ Passed PR描述清晰地解释了问题(Web和API域名分离部署中的配置示例问题)、解决方案(添加NEXT_PUBLIC_API_BASE_URL环境变量)和所做的更改(更新所有集成的示例以使用API源)。

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions github-actions Bot added bug Something isn't working area:UI area:docs labels Mar 29, 2026
Comment thread src/app/[locale]/usage-doc/page.tsx Outdated
const t = useTranslations("usage");
const resolvedOrigin = origin || t("ui.currentSiteAddress");
// 优先使用显式配置的 API 域名,兼容 Web/UI 与 API 分域部署
const apiOrigin = process.env.NEXT_PUBLIC_API_BASE_URL?.trim() || resolvedOrigin;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Trailing slash not sanitized from env-var value

String.prototype.trim() only removes whitespace. If an operator sets NEXT_PUBLIC_API_BASE_URL=https://api.example.com/ (with a trailing slash), every URL that appends a path segment will produce a double slash — e.g. https://api.example.com//v1/messages.

Consider stripping a trailing slash as well:

Suggested change
const apiOrigin = process.env.NEXT_PUBLIC_API_BASE_URL?.trim() || resolvedOrigin;
const apiOrigin = (process.env.NEXT_PUBLIC_API_BASE_URL?.trim() ?? "").replace(/\/$/, "") || resolvedOrigin;
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/app/[locale]/usage-doc/page.tsx
Line: 143

Comment:
**Trailing slash not sanitized from env-var value**

`String.prototype.trim()` only removes whitespace. If an operator sets `NEXT_PUBLIC_API_BASE_URL=https://api.example.com/` (with a trailing slash), every URL that appends a path segment will produce a double slash — e.g. `https://api.example.com//v1/messages`.

Consider stripping a trailing slash as well:

```suggestion
  const apiOrigin = (process.env.NEXT_PUBLIC_API_BASE_URL?.trim() ?? "").replace(/\/$/, "") || resolvedOrigin;
```

How can I resolve this? If you propose a fix, please make it concise.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces apiOrigin to support split-domain deployments, allowing the API base URL to be configured independently of the web origin via the NEXT_PUBLIC_API_BASE_URL environment variable. Documentation snippets for Claude, Gemini, and various model providers have been updated to use this new variable. Feedback indicates that the migration is incomplete in several sections of the documentation and that the Windows network connectivity test should be updated for consistency with the Unix version.

Comment thread src/app/[locale]/usage-doc/page.tsx Outdated
const t = useTranslations("usage");
const resolvedOrigin = origin || t("ui.currentSiteAddress");
// 优先使用显式配置的 API 域名,兼容 Web/UI 与 API 分域部署
const apiOrigin = process.env.NEXT_PUBLIC_API_BASE_URL?.trim() || resolvedOrigin;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

critical

While apiOrigin is correctly introduced to support split-domain deployments, its application is incomplete. Several documentation examples still use resolvedOrigin for API endpoints, which will generate incorrect URLs for users in split-domain deployments.

The following lines need to be updated to use apiOrigin instead of resolvedOrigin:

  • Line 1169
  • Line 1269
  • Line 1762


${t("snippets.comments.testNetworkConnection")}
curl -I ${resolvedOrigin}`}
curl -i ${apiOrigin}/v1/messages`}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

This update to the Unix network test is a great improvement. However, the corresponding test for Windows (on line 1510) was not updated. It still uses resolvedOrigin and a basic TCP check (Test-NetConnection).

For consistency and to provide an equivalent test, the Windows command should be updated to:

  1. Use apiOrigin.
  2. Use Invoke-WebRequest to test the /v1/messages endpoint, similar to this curl command.

Consider replacing the Test-NetConnection command with Invoke-WebRequest:

Invoke-WebRequest -Uri "${apiOrigin}/v1/messages" -UseBasicParsing

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: d0102dc0eb

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread src/app/[locale]/usage-doc/page.tsx Outdated
const t = useTranslations("usage");
const resolvedOrigin = origin || t("ui.currentSiteAddress");
// 优先使用显式配置的 API 域名,兼容 Web/UI 与 API 分域部署
const apiOrigin = process.env.NEXT_PUBLIC_API_BASE_URL?.trim() || resolvedOrigin;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Strip trailing slash from configured API origin

When NEXT_PUBLIC_API_BASE_URL is set with a trailing slash (a common format like https://api.example.com/), apiOrigin is used verbatim and later concatenated with suffixes such as /v1 and /v1beta, producing //v1 URLs in generated examples. Those double-slash paths can be treated differently by some gateways/SDKs (redirects or 404s), so users who copy these snippets may get connectivity failures even with a correct domain. Normalize trailing slashes before composing endpoint paths.

Useful? React with 👍 / 👎.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/app/[locale]/usage-doc/page.tsx (1)

1504-1519: ⚠️ Potential issue | 🟠 Major

Windows 的网络自检仍然在测 Web 域名。

Line 1510 继续从 resolvedOrigin 取主机,而且端口写死为 443。在 Web/UI 与 API 分域的部署里,Windows 用户会去探测前端域名而不是 API 域名;如果 API 用了非默认端口,这个示例也会给出错误结论。

建议修复
   const lang = os === "windows" ? "powershell" : "bash";
+  const apiConnectionTarget = (() => {
+    try {
+      const url = new URL(apiOrigin);
+      return {
+        host: url.hostname,
+        port: url.port || (url.protocol === "http:" ? "80" : "443"),
+      };
+    } catch {
+      return {
+        host: apiOrigin.replace(/^https?:\/\//, ""),
+        port: "443",
+      };
+    }
+  })();
...
- Test-NetConnection -ComputerName ${resolvedOrigin.replace("https://", "").replace("http://", "")} -Port 443
+ Test-NetConnection -ComputerName ${apiConnectionTarget.host} -Port ${apiConnectionTarget.port}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/app/`[locale]/usage-doc/page.tsx around lines 1504 - 1519, The Windows
Test-NetConnection snippet incorrectly uses resolvedOrigin and hardcodes port
443; change it to derive host and port from apiOrigin instead. In the component
rendering the PowerShell CodeBlock (referencing resolvedOrigin, apiOrigin,
envKeyName, t), parse apiOrigin with the URL API (new URL(apiOrigin)) to get
hostname and port, use the hostname for -ComputerName, and use the parsed port
if present otherwise fall back to 443 for -Port, then interpolate those
variables into the Test-NetConnection line in the CodeBlock.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/app/`[locale]/usage-doc/page.tsx:
- Around line 142-143: Normalize NEXT_PUBLIC_API_BASE_URL into an origin before
assigning to apiOrigin: read the raw value
(process.env.NEXT_PUBLIC_API_BASE_URL), trim it, then try to construct new
URL(raw) and use url.origin; if URL construction throws, fall back to stripping
any trailing slashes from the raw value (raw.replace(/\/+$/,'') ) and use that
only if non-empty, otherwise use resolvedOrigin; update the assignment for
apiOrigin (the variable in this file) accordingly so values like
"https://api.example.com/", "https://api.example.com/v1" or malformed values
won't produce path fragments in downstream examples.

---

Outside diff comments:
In `@src/app/`[locale]/usage-doc/page.tsx:
- Around line 1504-1519: The Windows Test-NetConnection snippet incorrectly uses
resolvedOrigin and hardcodes port 443; change it to derive host and port from
apiOrigin instead. In the component rendering the PowerShell CodeBlock
(referencing resolvedOrigin, apiOrigin, envKeyName, t), parse apiOrigin with the
URL API (new URL(apiOrigin)) to get hostname and port, use the hostname for
-ComputerName, and use the parsed port if present otherwise fall back to 443 for
-Port, then interpolate those variables into the Test-NetConnection line in the
CodeBlock.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 407178e4-c13b-4743-a252-f7581195d257

📥 Commits

Reviewing files that changed from the base of the PR and between b4192bb and d0102dc.

📒 Files selected for processing (1)
  • src/app/[locale]/usage-doc/page.tsx

Comment thread src/app/[locale]/usage-doc/page.tsx Outdated
Comment on lines +142 to +143
// 优先使用显式配置的 API 域名,兼容 Web/UI 与 API 分域部署
const apiOrigin = process.env.NEXT_PUBLIC_API_BASE_URL?.trim() || resolvedOrigin;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

先把 NEXT_PUBLIC_API_BASE_URL 归一化成 origin。

Line 143 现在只做了 trim()。如果部署把这个变量写成 https://api.example.com/https://api.example.com/v1,下面这些新示例会分别变成 //v1/v1/v1,本 PR 刚改到的 Claude/Codex/Gemini/OpenCode/Droid 配置都会一起误导用户。

建议修复
   const resolvedOrigin = origin || t("ui.currentSiteAddress");
-  const apiOrigin = process.env.NEXT_PUBLIC_API_BASE_URL?.trim() || resolvedOrigin;
+  const normalizeApiOrigin = (value: string) => {
+    const trimmed = value.trim();
+    try {
+      return new URL(trimmed).origin;
+    } catch {
+      return trimmed.replace(/\/+$/, "");
+    }
+  };
+  const apiOrigin = normalizeApiOrigin(
+    process.env.NEXT_PUBLIC_API_BASE_URL || resolvedOrigin,
+  );
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
// 优先使用显式配置的 API 域名,兼容 Web/UI 与 API 分域部署
const apiOrigin = process.env.NEXT_PUBLIC_API_BASE_URL?.trim() || resolvedOrigin;
const resolvedOrigin = origin || t("ui.currentSiteAddress");
// 优先使用显式配置的 API 域名,兼容 Web/UI 与 API 分域部署
const normalizeApiOrigin = (value: string) => {
const trimmed = value.trim();
try {
return new URL(trimmed).origin;
} catch {
return trimmed.replace(/\/+$/, "");
}
};
const apiOrigin = normalizeApiOrigin(
process.env.NEXT_PUBLIC_API_BASE_URL || resolvedOrigin,
);
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/app/`[locale]/usage-doc/page.tsx around lines 142 - 143, Normalize
NEXT_PUBLIC_API_BASE_URL into an origin before assigning to apiOrigin: read the
raw value (process.env.NEXT_PUBLIC_API_BASE_URL), trim it, then try to construct
new URL(raw) and use url.origin; if URL construction throws, fall back to
stripping any trailing slashes from the raw value (raw.replace(/\/+$/,'') ) and
use that only if non-empty, otherwise use resolvedOrigin; update the assignment
for apiOrigin (the variable in this file) accordingly so values like
"https://api.example.com/", "https://api.example.com/v1" or malformed values
won't produce path fragments in downstream examples.

@ding113

ding113 commented Apr 5, 2026

Copy link
Copy Markdown
Owner

hi,建议同步更新env.example文件。

xuesongjun and others added 2 commits April 11, 2026 12:56
- Fix Windows Test-NetConnection still using resolvedOrigin instead of apiOrigin
- Strip trailing slash from NEXT_PUBLIC_API_BASE_URL to prevent double-slash URLs

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Document the new env variable introduced for split-domain deployments.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

♻️ Duplicate comments (1)
src/app/[locale]/usage-doc/page.tsx (1)

142-143: ⚠️ Potential issue | 🟠 Major

请将 NEXT_PUBLIC_API_BASE_URL 规范化为纯 origin(而不是仅去尾斜杠)

Line 143 现在的处理会保留路径段。若配置为 https://api.example.com/v1,后续示例会出现 /v1/v1,且 Windows 网络检测命令也会拿到非法主机名。该问题在之前评审里提过,当前代码仍存在。

建议修复
   const resolvedOrigin = origin || t("ui.currentSiteAddress");
-  // 优先使用显式配置的 API 域名,兼容 Web/UI 与 API 分域部署
-  const apiOrigin = (process.env.NEXT_PUBLIC_API_BASE_URL?.trim() ?? "").replace(/\/$/, "") || resolvedOrigin;
+  // 优先使用显式配置的 API 域名,兼容 Web/UI 与 API 分域部署
+  const normalizeApiOrigin = (raw?: string) => {
+    const value = raw?.trim() ?? "";
+    if (!value) return resolvedOrigin;
+    try {
+      return new URL(value).origin;
+    } catch {
+      return value.replace(/\/+$/, "") || resolvedOrigin;
+    }
+  };
+  const apiOrigin = normalizeApiOrigin(process.env.NEXT_PUBLIC_API_BASE_URL);
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/app/`[locale]/usage-doc/page.tsx around lines 142 - 143, The current
apiOrigin assignment leaves path segments if NEXT_PUBLIC_API_BASE_URL includes
them; change the logic that computes apiOrigin (the const apiOrigin assignment)
to parse NEXT_PUBLIC_API_BASE_URL and normalize it to a pure origin (scheme +
host + optional port) before trimming and fallback to resolvedOrigin; e.g.,
detect if NEXT_PUBLIC_API_BASE_URL is non-empty, create a URL object or strip
everything after the host to obtain only the origin, and then use that
normalized origin in place of the raw trimmed value so examples and network
checks no longer inherit path segments.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Duplicate comments:
In `@src/app/`[locale]/usage-doc/page.tsx:
- Around line 142-143: The current apiOrigin assignment leaves path segments if
NEXT_PUBLIC_API_BASE_URL includes them; change the logic that computes apiOrigin
(the const apiOrigin assignment) to parse NEXT_PUBLIC_API_BASE_URL and normalize
it to a pure origin (scheme + host + optional port) before trimming and fallback
to resolvedOrigin; e.g., detect if NEXT_PUBLIC_API_BASE_URL is non-empty, create
a URL object or strip everything after the host to obtain only the origin, and
then use that normalized origin in place of the raw trimmed value so examples
and network checks no longer inherit path segments.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: e105ace9-0bd4-48c6-9720-9f53827f583b

📥 Commits

Reviewing files that changed from the base of the PR and between d0102dc and 9f0fe89.

📒 Files selected for processing (2)
  • .env.example
  • src/app/[locale]/usage-doc/page.tsx
✅ Files skipped from review due to trivial changes (1)
  • .env.example

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: a31e9ad46e

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

const t = useTranslations("usage");
const resolvedOrigin = origin || t("ui.currentSiteAddress");
// 优先使用显式配置的 API 域名,兼容 Web/UI 与 API 分域部署
const apiOrigin = (process.env.NEXT_PUBLIC_API_BASE_URL?.trim() ?? "").replace(/\/$/, "") || resolvedOrigin;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Resolve API origin from runtime config, not build-time env

This value is read inside a "use client" component, so process.env.NEXT_PUBLIC_API_BASE_URL is baked into the JS bundle at build time instead of read from container runtime env. In the default deployment path (docker-compose.yaml uses prebuilt ghcr.io/ding113/claude-code-hub:latest with .env injected at runtime), setting NEXT_PUBLIC_API_BASE_URL in .env will not change apiOrigin, so split-domain users still see incorrect examples unless they rebuild the image with that value.

Useful? React with 👍 / 👎.

@ding113
ding113 merged commit 81c3db1 into ding113:dev Apr 14, 2026
2 checks passed
@github-project-automation github-project-automation Bot moved this from Backlog to Done in Claude Code Hub Roadmap Apr 14, 2026
This was referenced Apr 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:docs area:UI bug Something isn't working

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants