This commit is contained in:
parent
8f408e03a9
commit
b16b726309
|
|
@ -14,29 +14,30 @@ import { BLOG_PATH, getContentData, getFilePaths, getPost, getQAContent } from "
|
||||||
import { getService } from "@/lib/http/service";
|
import { getService } from "@/lib/http/service";
|
||||||
import { Header, NavBack, TimeP } from "@/components/header";
|
import { Header, NavBack, TimeP } from "@/components/header";
|
||||||
import { baseTitle, baseURL, keywordsRoot } from "@/lib/metadata";
|
import { baseTitle, baseURL, keywordsRoot } from "@/lib/metadata";
|
||||||
|
import { getBaseUrl } from "@/lib/http/get-base-url"; // ✅ 不是 export 它,而是 import 用
|
||||||
|
|
||||||
export const runtime = "nodejs";
|
export const runtime = "nodejs";
|
||||||
|
|
||||||
// 推荐用法,async 获取
|
// // 推荐用法,async 获取
|
||||||
export async function getBaseUrl() {
|
// export async function getBaseUrl() {
|
||||||
let ip = await getRuntimeEnv("SUPABASE_URL");
|
// let ip = await getRuntimeEnv("SUPABASE_URL");
|
||||||
if (!ip) throw new Error("SUPABASE_URL 获取失败,无法构建 baseUrl");
|
// if (!ip) throw new Error("SUPABASE_URL 获取失败,无法构建 baseUrl");
|
||||||
|
|
||||||
// 判断协议
|
// // 判断协议
|
||||||
let protocol = "http";
|
// let protocol = "http";
|
||||||
if (
|
// if (
|
||||||
typeof window !== "undefined" &&
|
// typeof window !== "undefined" &&
|
||||||
window.location &&
|
// window.location &&
|
||||||
window.location.protocol === "https:"
|
// window.location.protocol === "https:"
|
||||||
) {
|
// ) {
|
||||||
protocol = "https";
|
// protocol = "https";
|
||||||
// ✅ 只在 HTTPS 客户端场景下用 hostname 替换 IP
|
// // ✅ 只在 HTTPS 客户端场景下用 hostname 替换 IP
|
||||||
ip = window.location.hostname;
|
// ip = window.location.hostname;
|
||||||
}
|
// }
|
||||||
|
|
||||||
// 拼接
|
// // 拼接
|
||||||
return `${protocol}://${ip}`;
|
// return `${protocol}://${ip}`;
|
||||||
}
|
// }
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
params: { locale: string, slug: string; title: string; description: string; authorName: string };
|
params: { locale: string, slug: string; title: string; description: string; authorName: string };
|
||||||
|
|
|
||||||
|
|
@ -16,3 +16,5 @@ export async function getBaseUrl() {
|
||||||
|
|
||||||
return `${protocol}://${ip}`;
|
return `${protocol}://${ip}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue