feat: default web API calls to same origin

This commit is contained in:
2026-05-01 08:35:06 +09:00
parent 7cfd50532d
commit 8656f237d4
7 changed files with 59 additions and 9 deletions

View File

@@ -0,0 +1,20 @@
import { describe, expect, test } from 'bun:test';
import { getApiBaseUrl } from '../src/lib/api-base.ts';
describe('getApiBaseUrl', () => {
test('uses the configured API base when provided', () => {
expect(getApiBaseUrl('https://api.example.com/', 'https://app.example.com')).toBe(
'https://api.example.com',
);
});
test('defaults to the current window origin when no API base is configured', () => {
expect(getApiBaseUrl(undefined, 'https://app.example.com/')).toBe(
'https://app.example.com',
);
});
test('falls back to localhost in non-browser contexts without configuration', () => {
expect(getApiBaseUrl(undefined, undefined)).toBe('http://localhost:3001');
});
});