diff --git a/apps/server/src/usage/cliproxyApi.test.ts b/apps/server/src/usage/cliproxyApi.test.ts index 5de08f9a0dc95..bb59266769e5a 100644 --- a/apps/server/src/usage/cliproxyApi.test.ts +++ b/apps/server/src/usage/cliproxyApi.test.ts @@ -73,7 +73,7 @@ function fixture( request, Response.json({}, { status: options.cooldownStatus ?? 200 }), ); - expect(path).toBe("/v0/management/api-call"); + expect(path).toMatch(/\/v0\/management\/api-call$/); expect(body?.header?.Authorization).toBe("Bearer $TOKEN$"); const upstream = options.upstream?.(body!) ?? { status: 200, @@ -145,6 +145,18 @@ describe("CLIProxyAPI built-in management API", () => { }), ); + it.effect("keeps the path of a hub served under a prefix", () => + Effect.gen(function* () { + const test = fixture(); + const api = yield* test.api; + yield* api.readAccounts({ ...config, url: "https://tools.test/cliproxy" }); + expect(test.requests.length).toBeGreaterThan(0); + expect( + test.requests.every((request) => request.path.startsWith("/cliproxy/v0/management/")), + ).toBe(true); + }), + ); + it.effect("keeps usage when the credits endpoint fails", () => Effect.gen(function* () { const test = fixture({ diff --git a/apps/server/src/usage/cliproxyApi.ts b/apps/server/src/usage/cliproxyApi.ts index b80ebe59261e7..cbc3fd9d8a2f3 100644 --- a/apps/server/src/usage/cliproxyApi.ts +++ b/apps/server/src/usage/cliproxyApi.ts @@ -131,7 +131,11 @@ export const makeCliproxyApi = Effect.gen(function* () { body?: unknown, ) { const url = yield* Effect.try({ - try: () => new URL(`/v0/management/${path}`, config.url).toString(), + try: () => + new URL( + `v0/management/${path}`, + config.url.endsWith("/") ? config.url : `${config.url}/`, + ).toString(), catch: () => new UsageLimitSourceError({ detail: "The hub URL is not valid." }), }); const request = (