Skip to content

Commit c6e3635

Browse files
committed
chore: default to location.origin in api base
1 parent 63cfe38 commit c6e3635

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

src/ui/apiBase.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ const stripTrailingSlashes = (s: string) => s.replace(/\/+$/, '');
88
*/
99
export const API_BASE = process.env.VITE_API_URI
1010
? stripTrailingSlashes(process.env.VITE_API_URI)
11-
: '';
11+
: location.origin;

test/ui/apiBase.test.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,14 @@ function loadApiBase() {
99
describe('apiBase', () => {
1010
let originalEnv;
1111

12+
before(() => {
13+
global.location = { origin: 'https://lovely-git-proxy.com' };
14+
});
15+
16+
after(() => {
17+
delete global.location;
18+
});
19+
1220
beforeEach(() => {
1321
originalEnv = process.env.VITE_API_URI;
1422
delete process.env.VITE_API_URI;
@@ -24,9 +32,9 @@ describe('apiBase', () => {
2432
delete require.cache[require.resolve('../../src/ui/apiBase')];
2533
});
2634

27-
it('uses empty string when VITE_API_URI is not set', () => {
35+
it('uses the location origin when VITE_API_URI is not set', () => {
2836
const { API_BASE } = loadApiBase();
29-
expect(API_BASE).to.equal('');
37+
expect(API_BASE).to.equal('https://lovely-git-proxy.com');
3038
});
3139

3240
it('returns the exact value when no trailing slash', () => {

0 commit comments

Comments
 (0)