소스 검색

fix: added headers invariant

Alexandru Cambose 3 달 전
부모
커밋
ac77e58015
1개의 변경된 파일2개의 추가작업 그리고 11개의 파일을 삭제
  1. 2 11
      apps/insights/src/utils/absolute-url.ts

+ 2 - 11
apps/insights/src/utils/absolute-url.ts

@@ -30,20 +30,11 @@ export async function absoluteUrl(pathname: string) {
     // if we have a host and a proto, we can construct the origin
     if (host && proto) origin = `${proto}://${host}`;
   } catch {
-    // headers() is unavailable
+    throw new Error("Headers are not available in this context. Please check where are you calling this function from.");
   }
 
-  // Fallbacks for requests where headers() is not available
   if (!origin) {
-    if (IS_PRODUCTION_SERVER) {
-      const productionUrl = demand("VERCEL_PROJECT_PRODUCTION_URL");
-      origin = `https://${productionUrl}`;
-    } else if (IS_PREVIEW_SERVER) {
-      const previewUrl = demand("VERCEL_URL");
-      origin = `https://${previewUrl}`;
-    } else {
-      origin = "http://localhost:3003";
-    }
+    throw new Error("No origin found! This should never happen.");
   }
 
   const path = pathname.startsWith("/") ? pathname : `/${pathname}`;