From b3a52f37f40a296f9e05f09e7b5755434512a1dc Mon Sep 17 00:00:00 2001 From: Sead Feng Date: Sat, 24 Aug 2024 20:37:51 +0800 Subject: [PATCH] fix protocol --- src/lib/utils.ts | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/lib/utils.ts b/src/lib/utils.ts index 9623e4b..f3aa14d 100644 --- a/src/lib/utils.ts +++ b/src/lib/utils.ts @@ -7,16 +7,13 @@ export function cn(...inputs: ClassValue[]) { return twMerge(clsx(inputs)) } export const getOrigin = ({ headers }: { headers: Headers }) => { - const host = headers.get('host') || appConfig.appDomain; - - const protocol = ['localhost', '127.0.0.1'].includes(host.split(":")[0]) ? 'http' : 'https'; - return `${protocol}://${host}`; + const url = new URL(headers.get("x-request-url")!); + return `${url.protocol}://${url.host}`; } export const getCanonical = ({ headers }: { headers: Headers }) => { - const origin = getOrigin({ headers }); const url = new URL(headers.get("x-request-url")!); - return `${origin}${url.pathname}`; + return `${url.protocol}://${url.host}${url.pathname}`; } export const createAlternates = ({ headers }: { headers: Headers; }) => {