Skip to content

Commit def17b2

Browse files
authored
fix(usage): a CLIProxyAPI hub served under a path keeps its path (pingdotgg#19336)
1 parent 02e9d24 commit def17b2

2 files changed

Lines changed: 18 additions & 2 deletions

File tree

‎apps/server/src/usage/cliproxyApi.test.ts‎

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ function fixture(
7373
request,
7474
Response.json({}, { status: options.cooldownStatus ?? 200 }),
7575
);
76-
expect(path).toBe("/v0/management/api-call");
76+
expect(path).toMatch(/\/v0\/management\/api-call$/);
7777
expect(body?.header?.Authorization).toBe("Bearer $TOKEN$");
7878
const upstream = options.upstream?.(body!) ?? {
7979
status: 200,
@@ -145,6 +145,18 @@ describe("CLIProxyAPI built-in management API", () => {
145145
}),
146146
);
147147

148+
it.effect("keeps the path of a hub served under a prefix", () =>
149+
Effect.gen(function* () {
150+
const test = fixture();
151+
const api = yield* test.api;
152+
yield* api.readAccounts({ ...config, url: "https://tools.test/cliproxy" });
153+
expect(test.requests.length).toBeGreaterThan(0);
154+
expect(
155+
test.requests.every((request) => request.path.startsWith("/cliproxy/v0/management/")),
156+
).toBe(true);
157+
}),
158+
);
159+
148160
it.effect("keeps usage when the credits endpoint fails", () =>
149161
Effect.gen(function* () {
150162
const test = fixture({

‎apps/server/src/usage/cliproxyApi.ts‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,11 @@ export const makeCliproxyApi = Effect.gen(function* () {
130130
body?: unknown,
131131
) {
132132
const url = yield* Effect.try({
133-
try: () => new URL(`/v0/management/${path}`, config.url).toString(),
133+
try: () =>
134+
new URL(
135+
`v0/management/${path}`,
136+
config.url.endsWith("/") ? config.url : `${config.url}/`,
137+
).toString(),
134138
catch: () => new UsageLimitSourceError({ detail: "The hub URL is not valid." }),
135139
});
136140
const request = (

0 commit comments

Comments
 (0)