fix(usage): a CLIProxyAPI hub served under a path keeps its path#19336

merged1
main
GitHub fork: fix/cliproxy-hub-base-path
opened18d agobyPPipyakas
View on GitHubTwo-way sync enabledPR last imported 11d ago

Problem

A CLIProxyAPI hub that sits behind a reverse proxy under a path, such as https://tools.example/cliproxy, can't be added as a usage source: every read fails with "The hub could not list accounts."

The cause is that cliproxyApi.ts builds the management URL as new URL("/v0/management/...", hubUrl). Because the path is absolute, it replaces the hub URL's own path, so the request goes to https://tools.example/v0/management/auth-files instead of https://tools.example/cliproxy/v0/management/auth-files.

Change

The management path is now resolved relative to the hub URL, with a trailing slash added when it's missing. A hub at the root of its host (http://192.168.1.100:8318) resolves to exactly the same URLs as before. A hub under a prefix now keeps that prefix.

Scope and approval

This is a very small fix for an obvious bug: the hub URL setting accepts any URL, but its path was silently dropped. The change is one URL expression plus a test, and nothing else changes behaviour.

Verification

  • Added keeps the path of a hub served under a prefix to cliproxyApi.test.ts. It reads accounts from https://tools.test/cliproxy and checks that every request path starts with /cliproxy/v0/management/.
  • The fixture's exact check on /v0/management/api-call now matches the suffix instead.
  • vp test run src/usage/cliproxyApi.test.ts: all 13 tests pass, including the existing root-URL cases.
  • I haven't tested this against a real prefixed hub yet.

Done with Claude Opus 5.5 in Claude Code.

Checks

23 successful · 7 skipped
All checks passed
ea289d2
Synced from GitHub

Approvability

Verdict: Approved at 1eb3a98

Macroscope's review found this PR approvable — This is a narrowly scoped URL-resolution fix that preserves existing root-host behavior while supporting CLIProxyAPI hubs mounted under a path. The production change is isolated and covered by a focused regression test, with no default, schema, deployment, or static-analysis changes.

You can add or adjust custom eligibility rules. Learn more.

Synced from GitHub

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Path: .coderabbit.config.ts
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 3f83f0fe-ff08-4be2-b524-f10abb38481f
📥 Commits

Reviewing files that changed from the base of the PR and between d10621de5f8f7e3af4831be04c0564a4ae65eade and 1eb3a9896a8bd440a77019bcd712262ae08a5c21.

📒 Files selected for processing: 2
  • apps/server/src/usage/cliproxyApi.test.ts
  • apps/server/src/usage/cliproxyApi.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

📝 Walkthrough

CliproxyApi.management now preserves path prefixes in the hub URL when building management URLs. Tests verify that readAccounts requests retain the /cliproxy prefix.

Changes: CLIProxy management URL prefixes

Layer / File(s)Summary
Build and verify prefixed management URLs
apps/server/src/usage/cliproxyApi.ts, apps/server/src/usage/cliproxyApi.test.ts
management resolves endpoints relative to the hub URL. Tests check that requests made by readAccounts retain the /cliproxy prefix.

Priority: ⬇️ Low

Estimated code review effort: 2 (Simple) | ~8 minutes

Change: Bug fix

Suggested reviewers: juliusmarminge

Merge Risk: ⚪ Minimal · up to 1eb3a

Management requests now retain the configured hub path, allowing hubs mounted behind a path prefix to be reached. The supplied regression test covers prefixed requests, and no actionable merge risk is evident.

Pre-merge checks: Passed 4
Passed Passed checks: 4 passed
Check nameStatusExplanation
Title checkPassedThe title clearly and concisely describes the main change: preserving a CLIProxyAPI hub path prefix when resolving management requests.
Description checkPassedThe description covers the problem, expected behavior, implementation, scope rationale, focused verification, test results, and the untested real-hub case. It matches the required template and is suff…
Linked Issues checkPassedCheck skipped because no linked issues were found for this pull request.
Out of Scope Changes checkPassedCheck skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

Added 1 commit

  • fix(usage): a CLIProxyAPI hub served under a path keeps its pathea289d2