This commit is contained in:
2026-04-14 18:05:32 +08:00
parent 68457c9fbd
commit 6378ab4994
40 changed files with 10488 additions and 113 deletions
+24
View File
@@ -0,0 +1,24 @@
import { headers } from "next/headers";
import { getEnv } from "@/lib/env";
export async function getRequestOrigin() {
const headerList = await headers();
const forwardedProto = headerList.get("x-forwarded-proto");
const forwardedHost = headerList.get("x-forwarded-host");
const host = forwardedHost || headerList.get("host");
if (!host) {
return getEnv().APP_URL;
}
const proto =
forwardedProto || (host.startsWith("localhost") || host.startsWith("127.0.0.1") ? "http" : "http");
return `${proto}://${host}`;
}
export function getOriginFromRequest(request: Request) {
const url = new URL(request.url);
return `${url.protocol}//${url.host}`;
}