From 072dce85175cbe58912da196f10b4620b994fcc3 Mon Sep 17 00:00:00 2001 From: hailin Date: Wed, 25 Jun 2025 17:04:05 +0800 Subject: [PATCH] . --- chatdesk-ui/app/[locale]/layout.tsx | 1 + .../utility/runtime-env-provider.tsx | 66 ++++++++++++++----- 2 files changed, 50 insertions(+), 17 deletions(-) diff --git a/chatdesk-ui/app/[locale]/layout.tsx b/chatdesk-ui/app/[locale]/layout.tsx index 7475fa2..b45e823 100644 --- a/chatdesk-ui/app/[locale]/layout.tsx +++ b/chatdesk-ui/app/[locale]/layout.tsx @@ -141,6 +141,7 @@ export default async function RootLayout({ src="/env.js" strategy="beforeInteractive" // 确保在 React 启动之前加载 /> */} + {/* ✅ 注入 window.RUNTIME_ENV.SUPABASE_URL */} diff --git a/chatdesk-ui/components/utility/runtime-env-provider.tsx b/chatdesk-ui/components/utility/runtime-env-provider.tsx index bde082d..8c687fe 100644 --- a/chatdesk-ui/components/utility/runtime-env-provider.tsx +++ b/chatdesk-ui/components/utility/runtime-env-provider.tsx @@ -50,43 +50,75 @@ // app/_runtime-env-provider.tsx (务必保持在 app 目录 ➜ Server 组件) +// import { headers } from "next/headers" +// import { useServerInsertedHTML } from "next/navigation" +// import React from "react" + +// export function RuntimeEnvProvider({ children }: { children: React.ReactNode }) { +// /* 解析请求头 */ +// const h = headers() +// console.log("[RuntimeEnv] Raw headers:", Object.fromEntries(h.entries())) + +// const proto = +// h.get("x-forwarded-proto") ?? +// (h.get("host")?.includes(":443") ? "https" : "http") +// console.log("[RuntimeEnv] Resolved protocol:", proto) + +// const rawHost = h.get("x-forwarded-host") ?? h.get("host")! +// console.log("[RuntimeEnv] rawHost :", rawHost) + +// const hostname = rawHost.split(",")[0].split(":")[0].trim() +// console.log("[RuntimeEnv] hostname :", hostname) + +// const supabaseUrl = `${proto}://${hostname}:8000` +// console.log("[RuntimeEnv] supabaseUrl to inject:", supabaseUrl) + +// /* 把脚本塞进 HTML(这一行如果不打印,说明没执行) */ +// useServerInsertedHTML(() => { +// console.log("[RuntimeEnv]