From b2c988fc1be9e7821ebcd4fbe03c5c04225a0703 Mon Sep 17 00:00:00 2001 From: hailin Date: Sun, 15 Jun 2025 16:54:21 +0800 Subject: [PATCH] . --- .../app/[locale]/details/[slug]/page.tsx | 20 ------------- apps/blogai/lib/http/get-base-url.ts | 29 ++++++++++++++++--- 2 files changed, 25 insertions(+), 24 deletions(-) diff --git a/apps/blogai/app/[locale]/details/[slug]/page.tsx b/apps/blogai/app/[locale]/details/[slug]/page.tsx index b94a840..0c20e7c 100644 --- a/apps/blogai/app/[locale]/details/[slug]/page.tsx +++ b/apps/blogai/app/[locale]/details/[slug]/page.tsx @@ -17,7 +17,6 @@ import { baseTitle, baseURL, keywordsRoot } from "@/lib/metadata"; import { useTranslation } from "react-i18next"; import { DetailPageHeader } from '@/components/header' -//import { getRuntimeEnv } from "@/lib/ipconfig"; import { getBaseUrl } from "@/lib/http/get-base-url"; // ✅ 不是 export 它,而是 import 用 export const runtime = "nodejs"; @@ -27,25 +26,6 @@ type Props = { searchParams: { [key: string]: string | string[] | undefined }; }; -// // 推荐用法,async 获取 -// export async function getBaseUrl() { -// let ip = await getRuntimeEnv("SUPABASE_URL"); -// if (!ip) throw new Error("SUPABASE_URL 获取失败,无法构建 baseUrl"); - -// // 判断协议 -// let protocol = "http"; -// if ( -// typeof window !== "undefined" && -// window.location && -// window.location.protocol === "https:" -// ) { -// protocol = "https"; -// ip = window.location.hostname; // ✅ HTTPS 场景下安全替换 IP 为域名 -// } - -// // 拼接 -// return `${protocol}://${ip}`; -// } export async function generateMetadata({ params }: Props): Promise { diff --git a/apps/blogai/lib/http/get-base-url.ts b/apps/blogai/lib/http/get-base-url.ts index a30913b..43b4a89 100644 --- a/apps/blogai/lib/http/get-base-url.ts +++ b/apps/blogai/lib/http/get-base-url.ts @@ -1,10 +1,32 @@ -import { getRuntimeEnv } from "@/lib/ipconfig"; +// import { getRuntimeEnv } from "@/lib/ipconfig"; + +// export async function getBaseUrl() { +// let ip = await getRuntimeEnv("SUPABASE_URL"); +// if (!ip) throw new Error("SUPABASE_URL 获取失败,无法构建 baseUrl"); + +// let protocol = "http"; +// if ( +// typeof window !== "undefined" && +// window.location && +// window.location.protocol === "https:" +// ) { +// protocol = "https"; +// ip = window.location.hostname; +// } + +// return `${protocol}://${ip}`; +// } + + + export async function getBaseUrl() { let ip = await getRuntimeEnv("SUPABASE_URL"); if (!ip) throw new Error("SUPABASE_URL 获取失败,无法构建 baseUrl"); let protocol = "http"; + let port = 80; + if ( typeof window !== "undefined" && window.location && @@ -12,9 +34,8 @@ export async function getBaseUrl() { ) { protocol = "https"; ip = window.location.hostname; + port = 443; } - return `${protocol}://${ip}`; + return `${protocol}://${ip}:${port}`; } - -