Skip to content

Commit 07371a1

Browse files
authored
feat: update site URL to follow Next.js logic
1 parent f0e95f4 commit 07371a1

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

src/constants/site-config.ts

+8-3
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ export const routes = {
1717
params: { name: "Parameters", pathname: "/_params" },
1818
} as const satisfies Record<string, Route>;
1919

20+
// ref: https://nextjs.org/docs/app/api-reference/functions/generate-metadata#default-value
2021
const getSiteUrl = () => {
2122
if (
2223
process.env.NEXT_PUBLIC_VERCEL_ENV === "production" &&
@@ -26,10 +27,14 @@ const getSiteUrl = () => {
2627
}
2728

2829
if (
29-
process.env.NEXT_PUBLIC_VERCEL_ENV &&
30-
process.env.NEXT_PUBLIC_VERCEL_URL
30+
process.env.NEXT_PUBLIC_VERCEL_ENV === "preview" &&
31+
(process.env.NEXT_PUBLIC_VERCEL_BRANCH_URL ||
32+
process.env.NEXT_PUBLIC_VERCEL_URL)
3133
) {
32-
return `https://${process.env.NEXT_PUBLIC_VERCEL_URL}`;
34+
return `https://${
35+
process.env.NEXT_PUBLIC_VERCEL_BRANCH_URL ??
36+
process.env.NEXT_PUBLIC_VERCEL_URL
37+
}`;
3338
}
3439

3540
return `http://localhost:${process.env.PORT ?? 3000}`;

0 commit comments

Comments
 (0)