Skip to content

Commit 19dda01

Browse files
fix: Bazarr CLI uses wrong API base path (#104) (#105)
Fixes double-prefixed URLs by stripping /api from base URL, since generated SDK paths already include /api/ prefix. Also corrects doctor check and response unwrapping for Bazarr's {"data": {...}} response format. Co-authored-by: Claude Haiku 4.5 <noreply@anthropic.com>
1 parent 38281c9 commit 19dda01

2 files changed

Lines changed: 7 additions & 6 deletions

File tree

src/clients/bazarr.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@ import { client as bazarrClient } from '../generated/bazarr/client.gen.js';
44
import * as BazarrApi from '../generated/bazarr/index.js';
55

66
function getBazarrApiBaseUrl(baseUrl: string): string {
7-
const normalizedBaseUrl = baseUrl.replace(/\/$/, '');
8-
return normalizedBaseUrl.endsWith('/api') ? normalizedBaseUrl : `${normalizedBaseUrl}/api`;
7+
// Generated SDK paths already include /api/ prefix, so strip it from the base URL
8+
// to avoid double-prefixing (e.g. /api/api/system/status)
9+
return baseUrl.replace(/\/+$/, '').replace(/\/api$/, '');
910
}
1011

1112
function getBazarrHeaders(config: ReturnType<typeof createServarrClient>) {

tests/clients-unit.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -424,18 +424,18 @@ describe('Client Unit Tests', () => {
424424
expect(client).toBeInstanceOf(BazarrClient);
425425
});
426426

427-
it('should configure the raw client with the /api prefix', () => {
427+
it('should configure the raw client without /api prefix (SDK paths include it)', () => {
428428
new BazarrClient(validConfig);
429-
expect(bazarrApiClient.getConfig().baseUrl).toBe('http://localhost:6767/api');
429+
expect(bazarrApiClient.getConfig().baseUrl).toBe('http://localhost:6767');
430430
});
431431

432-
it('should not duplicate the /api prefix when already present', () => {
432+
it('should strip /api suffix when user includes it in base URL', () => {
433433
new BazarrClient({
434434
baseUrl: 'http://localhost:6767/api',
435435
apiKey: 'valid-api-key',
436436
});
437437

438-
expect(bazarrApiClient.getConfig().baseUrl).toBe('http://localhost:6767/api');
438+
expect(bazarrApiClient.getConfig().baseUrl).toBe('http://localhost:6767');
439439
});
440440

441441
it('should configure generated auth for Bazarr requests', () => {

0 commit comments

Comments
 (0)