From f31df7fbc8e1311ccc4e84f8988e3f4b777d104e Mon Sep 17 00:00:00 2001 From: hailin Date: Wed, 21 May 2025 15:02:30 +0800 Subject: [PATCH] . --- chatdesk-ui/app/[locale]/layout.tsx | 37 +++++++++++++++++++++++++---- 1 file changed, 33 insertions(+), 4 deletions(-) diff --git a/chatdesk-ui/app/[locale]/layout.tsx b/chatdesk-ui/app/[locale]/layout.tsx index 2ef118a..5471cc5 100644 --- a/chatdesk-ui/app/[locale]/layout.tsx +++ b/chatdesk-ui/app/[locale]/layout.tsx @@ -28,6 +28,26 @@ interface RootLayoutProps { } } + + +// 新增的 `getValidSupabaseUrl` 函数,带有超时机制和错误处理 +async function getValidSupabaseUrl(): Promise { + let url = getRuntimeEnv("SUPABASE_URL"); + const timeout = Date.now() + 30000; // 设置最大等待时间为30秒 + + while (!url || !url.includes(":")) { // 检查是否包含合法的 IP 和端口 + if (Date.now() > timeout) { + throw new Error("获取有效的 Supabase URL 超时"); + } + console.log("等待有效的 Supabase URL..."); + await new Promise(resolve => setTimeout(resolve, 1000)); // 每1秒检查一次 + url = getRuntimeEnv("SUPABASE_URL"); + } + return url; +} + + + export async function generateMetadata({ params: { locale } }: { @@ -93,9 +113,20 @@ export default async function RootLayout({ console.log(`🍪 Cookie: ${cookie.name} = ${cookie.value}`); } - const supabaseUrl = getRuntimeEnv("SUPABASE_URL"); - console.log("=================>Server's Supabase URL: ", supabaseUrl); + // const supabaseUrl = getRuntimeEnv("SUPABASE_URL"); + // console.log("==========>Supabase URL: ", supabaseUrl); + + let supabaseUrl = ""; + try { + // 等待直到获取到有效的 Supabase URL + supabaseUrl = await getValidSupabaseUrl(); + console.log("获取到有效的 Supabase URL: ", supabaseUrl); + } catch (error) { + console.error("Supabase URL 获取失败:", error); + return
获取 Supabase 配置失败,请稍后再试。
; // 出现错误时返回一个友好的提示 + } + // const supabase = createServerClient( // getRuntimeEnv("SUPABASE_URL") ?? "http://localhost:8000", // process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY!, @@ -119,8 +150,6 @@ export default async function RootLayout({ const { t, resources } = await initTranslations(locale, i18nNamespaces) - //console.log("[layout.tsx]..............current locale: ", {locale}); - return (