mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-07-24 06:15:19 +00:00
Fix getApiBase() returning https://undefined when API_DOMAIN unset (#4685)
Resolves #4684 ## Description: Fixes `getApiBase()` returning `https://undefined` on `localhost` when `API_DOMAIN` is unset (a plain `npm run dev`). - `src/client/Api.ts`: use the exact `process.env.API_DOMAIN` form so Vite's `define` replaces it (the previous `process?.env?.API_DOMAIN` optional-chaining form wasn't matched, leaving the literal string `"undefined"`). - `vite.config.ts`: `JSON.stringify(env.API_DOMAIN ?? "")` so an unset value becomes a falsy empty string instead of the truthy string `"undefined"`. Net: an unset `API_DOMAIN` now falls back to `http://localhost:8787` as intended. ## Please complete the following: - [x] I have added screenshots for all UI updates — _no UI changes_ - [x] I process any text displayed to the user through translateText() and I've added it to the en.json file — _no user-facing text_ - [x] I have added relevant tests to the test directory — new `tests/Api.test.ts` reproduces `https://undefined` (RED) and asserts the `http://localhost:8787` fallback (GREEN); full suite green (2149 tests) ## Please put your Discord username so you can be contacted if a bug or regression is found: _⚠️ maintainer to fill_ 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01BWxUzYb2uqjcBFQuNSJhMy
This commit is contained in:
@@ -0,0 +1,15 @@
|
||||
import { beforeEach, describe, expect, it } from "vitest";
|
||||
import { getApiBase } from "../src/client/Api";
|
||||
|
||||
describe("getApiBase", () => {
|
||||
beforeEach(() => {
|
||||
localStorage.clear();
|
||||
});
|
||||
|
||||
// API_DOMAIN is forced empty under vitest via the vite.config `define`, so this
|
||||
// regression test exercises the fallback branch deterministically regardless of
|
||||
// any API_DOMAIN in the host shell / CI.
|
||||
it("falls back to http://localhost:8787 on localhost when apiHost is not set and API_DOMAIN is empty", () => {
|
||||
expect(getApiBase()).toBe("http://localhost:8787");
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user