chatdesk-ui/chatdesk-ui/lib/runtime-env/server.ts

14 lines
498 B
TypeScript

// lib/runtime-env/server.ts
import { headers } from "next/headers"
export function getRuntimeEnvServer(key: string): string | undefined {
if (key === "SUPABASE_URL") {
const h = headers()
const proto = h.get("x-forwarded-proto") ?? (h.get("host")?.includes(":443") ? "https" : "http")
const rawHost = h.get("x-forwarded-host") ?? h.get("host")!
const hostname = rawHost.split(",")[0].split(":")[0].trim()
return `${proto}://${hostname}:8000`
}
return process.env[key]
}