Files
deerflow-code/frontend-web/src/env.ts
T

34 lines
1.3 KiB
TypeScript

type EnvValue = string | undefined;
declare global {
interface Window {
__CM_RUNTIME_CONFIG__?: Record<string, string | undefined>;
}
}
export function readRuntimeEnv(key: string): EnvValue {
const runtimeValue =
typeof window !== "undefined" ? window.__CM_RUNTIME_CONFIG__?.[key] : undefined;
if (typeof runtimeValue === "string" && runtimeValue.trim()) {
return runtimeValue.trim();
}
const value = import.meta.env[key];
return typeof value === "string" && value.trim() ? value : undefined;
}
export function readRuntimeFlag(key: string): boolean {
return readRuntimeEnv(key) === "true";
}
export const env = {
NEXT_PUBLIC_BACKEND_BASE_URL: readRuntimeEnv("VITE_BACKEND_BASE_URL"),
NEXT_PUBLIC_LANGGRAPH_BASE_URL: readRuntimeEnv("VITE_LANGGRAPH_BASE_URL"),
// Canvas page uses its own LangGraph base URL so it can be independently
// routed (e.g. a separate canvas-agent server). Falls back to the main URL.
NEXT_PUBLIC_CANVAS_LANGGRAPH_BASE_URL: readRuntimeEnv("VITE_CANVAS_LANGGRAPH_BASE_URL"),
NEXT_PUBLIC_NOTE_API_BASE_URL: readRuntimeEnv("VITE_NOTE_API_BASE_URL"),
NEXT_PUBLIC_NOTEBOOK_API_BASE_URL: readRuntimeEnv("VITE_AIPI_BACKENP_URL"),
NEXT_PUBLIC_STATIC_WEBSITE_ONLY: readRuntimeEnv("VITE_STATIC_WEBSITE_ONLY"),
GITHUB_OAUTH_TOKEN: readRuntimeEnv("VITE_GITHUB_OAUTH_TOKEN"),
};