feat: default web API calls to same origin
This commit is contained in:
20
apps/web/test/api-base.test.js
Normal file
20
apps/web/test/api-base.test.js
Normal 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');
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user