Selaa lähdekoodia

fix: added headers invariant

Alexandru Cambose 3 kuukautta sitten
vanhempi
sitoutus
ac77e58015
1 muutettua tiedostoa jossa 2 lisäystä ja 11 poistoa
  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}`;