hts/apps/blogai/lib/http/get-base-url.ts

43 lines
996 B
TypeScript

// 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}`;
// }
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";
let port = 80;
if (
typeof window !== "undefined" &&
window.location &&
window.location.protocol === "https:"
) {
protocol = "https";
ip = window.location.hostname;
port = 443;
}
return `${protocol}://${ip}:${port}`;
}