hts/apps/blogai/lib/http/getServerBaseUrl.ts

12 lines
334 B
TypeScript

// lib/http/getServerBaseUrl.ts
import { headers } from "next/headers";
export function getServerBaseUrl(defaultIp: string) {
const h = headers();
const proto = h.get("x-forwarded-proto") || "http";
const host = h.get("host") || defaultIp;
const port = proto === "https" ? 443 : 80;
return `${proto}://${host}:${port}`;
}