Download src/lib/env.ts from asnannp/DocDoeAI: direct link, hf CLI and curl.
- Browser
- Download file 1.88 kB
-
https://huggingface.co/spaces/asnannp/DocDoeAI/resolve/main/src/lib/env.ts
- Command line
-
hf download hf://spaces/asnannp/DocDoeAI/src/lib/env.ts
-
curl -L -o env.ts https://huggingface.co/spaces/asnannp/DocDoeAI/resolve/main/src/lib/env.ts
1.88 kB
| const DEFAULT_API_BASE_URL = process.env.NODE_ENV === "production" | |
| ? "https://asnannp-docdoeai.hf.space" | |
| : "http://127.0.0.1:8000"; | |
| const DEFAULT_API_TIMEOUT_MS = 30000; | |
| const DEFAULT_POLL_INTERVAL_MS = 5000; | |
| const publicEnv = { | |
| NEXT_PUBLIC_API_BASE_URL: process.env.NEXT_PUBLIC_API_BASE_URL, | |
| NEXT_PUBLIC_API_URL: process.env.NEXT_PUBLIC_API_URL, | |
| NEXT_PUBLIC_API_TIMEOUT_MS: process.env.NEXT_PUBLIC_API_TIMEOUT_MS, | |
| NEXT_PUBLIC_POLL_INTERVAL_MS: process.env.NEXT_PUBLIC_POLL_INTERVAL_MS, | |
| NEXT_PUBLIC_DEMO_MODE: process.env.NEXT_PUBLIC_DEMO_MODE, | |
| } as const; | |
| function readPublicEnv(name: keyof typeof publicEnv) { | |
| return publicEnv[name]?.trim(); | |
| } | |
| export function getPublicApiBaseUrl() { | |
| const configured = | |
| readPublicEnv("NEXT_PUBLIC_API_BASE_URL") || | |
| readPublicEnv("NEXT_PUBLIC_API_URL") || | |
| DEFAULT_API_BASE_URL; | |
| return configured.replace(/\/$/, ""); | |
| } | |
| export function getPublicApiTimeoutMs() { | |
| const configured = Number(readPublicEnv("NEXT_PUBLIC_API_TIMEOUT_MS")); | |
| return Number.isFinite(configured) && configured > 0 ? configured : DEFAULT_API_TIMEOUT_MS; | |
| } | |
| export function getPublicPollIntervalMs() { | |
| const configured = Number(readPublicEnv("NEXT_PUBLIC_POLL_INTERVAL_MS")); | |
| return Number.isFinite(configured) && configured > 0 ? configured : DEFAULT_POLL_INTERVAL_MS; | |
| } | |
| export type PublicDemoMode = "demo" | "live" | "auto"; | |
| /** Resolves NEXT_PUBLIC_DEMO_MODE for API + auth behavior (demo / live / auto). */ | |
| export function getPublicDemoMode(): PublicDemoMode { | |
| const configured = readPublicEnv("NEXT_PUBLIC_DEMO_MODE")?.toLowerCase(); | |
| if (configured === "demo" || configured === "explicit") { | |
| return "demo"; | |
| } | |
| if (configured === "live" || configured === "false") { | |
| return "live"; | |
| } | |
| if (configured === "auto") { | |
| return "auto"; | |
| } | |
| return process.env.NODE_ENV === "production" ? "live" : "auto"; | |
| } | |