diff --git a/apps/admin/src/lib/api.test.ts b/apps/admin/src/lib/api.test.ts new file mode 100644 index 0000000..7ed9724 --- /dev/null +++ b/apps/admin/src/lib/api.test.ts @@ -0,0 +1,15 @@ +import { describe, expect, it } from "vitest"; +import { resolveAdminApiBaseUrl } from "./api"; + +describe("resolveAdminApiBaseUrl", () => { + it("pins the deployed admin panel to the production api", () => { + expect(resolveAdminApiBaseUrl("production", "https://api-staging.xtablo.com/api/v1")).toBe( + "https://api.xtablo.com/api/v1" + ); + expect(resolveAdminApiBaseUrl("production")).toBe("https://api.xtablo.com/api/v1"); + }); + + it("keeps localhost for local development", () => { + expect(resolveAdminApiBaseUrl("development")).toBe("http://localhost:8080/api/v1"); + }); +}); diff --git a/apps/admin/src/lib/api.ts b/apps/admin/src/lib/api.ts index 7db3ca1..5ddfcdb 100644 --- a/apps/admin/src/lib/api.ts +++ b/apps/admin/src/lib/api.ts @@ -1,7 +1,18 @@ import { buildApi } from "@xtablo/shared"; import { getStoredAdminSession } from "./adminSession"; -const apiBaseUrl = import.meta.env.VITE_API_URL || "http://localhost:8080/api/v1"; +const LOCAL_ADMIN_API_BASE_URL = "http://localhost:8080/api/v1"; +const PRODUCTION_ADMIN_API_BASE_URL = "https://api.xtablo.com/api/v1"; + +export function resolveAdminApiBaseUrl(mode = import.meta.env.MODE, _envApiUrl?: string) { + if (mode === "development") { + return LOCAL_ADMIN_API_BASE_URL; + } + + return PRODUCTION_ADMIN_API_BASE_URL; +} + +const apiBaseUrl = resolveAdminApiBaseUrl(); export const adminApi = buildApi(apiBaseUrl); diff --git a/apps/admin/tsconfig.tsbuildinfo b/apps/admin/tsconfig.tsbuildinfo index bbb6911..2e651c2 100644 --- a/apps/admin/tsconfig.tsbuildinfo +++ b/apps/admin/tsconfig.tsbuildinfo @@ -1 +1 @@ -{"root":["./src/app.tsx","./src/main.tsx","./src/routes.test.tsx","./src/routes.tsx","./src/setuptests.ts","./src/components/adminlayout.test.tsx","./src/components/adminlayout.tsx","./src/components/adminnavigation.tsx","./src/components/privilegedgate.test.tsx","./src/components/privilegedgate.tsx","./src/components/productionbadge.tsx","./src/components/actions/actionrunner.tsx","./src/components/analytics/chartbuilder.tsx","./src/components/analytics/saveddashboardlist.tsx","./src/components/data-explorer/admingrid.tsx","./src/components/data-explorer/roweditform.test.tsx","./src/components/data-explorer/roweditform.tsx","./src/hooks/useadminactions.ts","./src/hooks/useadmindatasets.ts","./src/hooks/useadminoverview.ts","./src/hooks/useadminsession.ts","./src/hooks/useadmintables.ts","./src/lib/adminsession.ts","./src/lib/api.ts","./src/pages/actioncenterpage.test.tsx","./src/pages/actioncenterpage.tsx","./src/pages/analyticsstudiopage.test.tsx","./src/pages/analyticsstudiopage.tsx","./src/pages/dataexplorerpage.test.tsx","./src/pages/dataexplorerpage.tsx","./src/pages/operationshomepage.tsx","./src/registry/actions.ts","./src/registry/datasets.ts","./worker/index.test.ts","./worker/index.ts"],"version":"5.9.3"} \ No newline at end of file +{"root":["./src/app.tsx","./src/main.tsx","./src/routes.test.tsx","./src/routes.tsx","./src/setuptests.ts","./src/components/adminlayout.test.tsx","./src/components/adminlayout.tsx","./src/components/adminnavigation.tsx","./src/components/privilegedgate.test.tsx","./src/components/privilegedgate.tsx","./src/components/productionbadge.tsx","./src/components/actions/actionrunner.tsx","./src/components/analytics/chartbuilder.tsx","./src/components/analytics/saveddashboardlist.tsx","./src/components/data-explorer/admingrid.tsx","./src/components/data-explorer/roweditform.test.tsx","./src/components/data-explorer/roweditform.tsx","./src/hooks/useadminactions.ts","./src/hooks/useadmindatasets.ts","./src/hooks/useadminoverview.ts","./src/hooks/useadminsession.ts","./src/hooks/useadmintables.ts","./src/lib/adminsession.ts","./src/lib/api.test.ts","./src/lib/api.ts","./src/pages/actioncenterpage.test.tsx","./src/pages/actioncenterpage.tsx","./src/pages/analyticsstudiopage.test.tsx","./src/pages/analyticsstudiopage.tsx","./src/pages/dataexplorerpage.test.tsx","./src/pages/dataexplorerpage.tsx","./src/pages/operationshomepage.tsx","./src/registry/actions.ts","./src/registry/datasets.ts","./worker/index.test.ts","./worker/index.ts"],"version":"5.9.3"} \ No newline at end of file