diff --git a/src/frontend.tsx b/src/frontend.tsx index ed6a42d..b632040 100644 --- a/src/frontend.tsx +++ b/src/frontend.tsx @@ -13,7 +13,7 @@ import { Inspector } from "react-dev-inspector"; import { createRoot } from "react-dom/client"; import { routeTree } from "./routeTree.gen"; import { ModalsProvider } from "@mantine/modals"; -import { VITE_PUBLIC_URL } from "./utils/env"; +import { VITE_PUBLIC_URL, IS_DEV } from "./utils/env"; // Create a new router instance export const router = createRouter({ @@ -32,7 +32,7 @@ const theme = createTheme({ /** Theme customization here */ }); -const InspectorWrapper = import.meta.env.DEV +const InspectorWrapper = IS_DEV ? Inspector : ({ children }: { children: React.ReactNode }) => <>{children}; diff --git a/src/utils/api-client.ts b/src/utils/api-client.ts index 461fd7b..f8db9a4 100644 --- a/src/utils/api-client.ts +++ b/src/utils/api-client.ts @@ -1,8 +1,9 @@ import { edenTreaty } from "@elysiajs/eden"; import type { ApiApp } from "../index"; +import { VITE_PUBLIC_URL } from "./env"; const baseUrl = - import.meta.env.VITE_PUBLIC_URL || + VITE_PUBLIC_URL || (typeof window !== "undefined" ? window.location.origin : "http://localhost:3000"); diff --git a/src/utils/env.ts b/src/utils/env.ts index 466bd4d..b224c93 100644 --- a/src/utils/env.ts +++ b/src/utils/env.ts @@ -21,3 +21,11 @@ export const getEnv = (key: string, defaultValue = ""): string => { }; export const VITE_PUBLIC_URL = getEnv("VITE_PUBLIC_URL", "http://localhost:3000"); + +export const IS_DEV = (() => { + try { + return typeof import.meta.env !== "undefined" && import.meta.env.DEV; + } catch { + return false; + } +})();