fix: 移除前端 API 环境入口

This commit is contained in:
Cheng Zhou
2026-03-31 09:44:49 +08:00
parent 84f865a7b0
commit ba880dad9a
4 changed files with 1 additions and 36 deletions
-1
View File
@@ -1,5 +1,4 @@
# Frontend feature flags and timeline overrides
VITE_API_BASE_URL=
VITE_STARTUP_SUBMIT_ACCEPT_TIMEOUT_MONTHS=3
VITE_STARTUP_ACCEPT_TIMEOUT_MONTHS=3
VITE_STARTUP_ACCEPT_APPROVAL_TIMEOUT_MONTHS=6
+1 -4
View File
@@ -7,12 +7,9 @@ import { useStudyStore } from "../store/study";
import { TEXT } from "../locales";
import { extendAccessToken, forceLogout, lockSession, markNetworkActive } from "../session/sessionManager";
import { useSessionStore } from "../store/session";
import { resolveApiBaseUrl } from "./baseUrl";
const apiBaseUrl = resolveApiBaseUrl(import.meta.env.VITE_API_BASE_URL);
const instance: AxiosInstance = axios.create({
baseURL: apiBaseUrl,
baseURL: "/",
timeout: 15000,
});
-19
View File
@@ -1,19 +0,0 @@
import { describe, expect, it } from "vitest";
import { resolveApiBaseUrl } from "./baseUrl";
describe("resolveApiBaseUrl", () => {
it("defaults to same-origin root when no env override is set", () => {
expect(resolveApiBaseUrl(undefined)).toBe("/");
expect(resolveApiBaseUrl("")).toBe("/");
expect(resolveApiBaseUrl(" ")).toBe("/");
});
it("preserves explicit root", () => {
expect(resolveApiBaseUrl("/")).toBe("/");
});
it("trims whitespace and trailing slashes from absolute base urls", () => {
expect(resolveApiBaseUrl(" http://localhost:8000/ ")).toBe("http://localhost:8000");
expect(resolveApiBaseUrl("https://api.example.com///")).toBe("https://api.example.com");
});
});
-12
View File
@@ -1,12 +0,0 @@
const trimTrailingSlashes = (value: string): string => value.replace(/\/+$/, "");
export const resolveApiBaseUrl = (rawValue: string | undefined): string => {
const normalized = rawValue?.trim() ?? "";
if (!normalized) {
return "/";
}
if (normalized === "/") {
return "/";
}
return trimTrailingSlashes(normalized);
};