Skip to content

Commit ac77e58

Browse files
committed
fix: added headers invariant
1 parent 44e489b commit ac77e58

File tree

1 file changed

+2
-11
lines changed

1 file changed

+2
-11
lines changed

apps/insights/src/utils/absolute-url.ts

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -30,20 +30,11 @@ export async function absoluteUrl(pathname: string) {
3030
// if we have a host and a proto, we can construct the origin
3131
if (host && proto) origin = `${proto}://${host}`;
3232
} catch {
33-
// headers() is unavailable
33+
throw new Error("Headers are not available in this context. Please check where are you calling this function from.");
3434
}
3535

36-
// Fallbacks for requests where headers() is not available
3736
if (!origin) {
38-
if (IS_PRODUCTION_SERVER) {
39-
const productionUrl = demand("VERCEL_PROJECT_PRODUCTION_URL");
40-
origin = `https://${productionUrl}`;
41-
} else if (IS_PREVIEW_SERVER) {
42-
const previewUrl = demand("VERCEL_URL");
43-
origin = `https://${previewUrl}`;
44-
} else {
45-
origin = "http://localhost:3003";
46-
}
37+
throw new Error("No origin found! This should never happen.");
4738
}
4839

4940
const path = pathname.startsWith("/") ? pathname : `/${pathname}`;

0 commit comments

Comments
 (0)