Skip to content
This repository was archived by the owner on Jan 23, 2025. It is now read-only.

Commit fd3e0f2

Browse files
Update helpers.ts
Handle empty as well as missing env variables
1 parent c7867b2 commit fd3e0f2

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

utils/helpers.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,13 @@ type Price = Database['public']['Tables']['prices']['Row'];
44

55
export const getURL = () => {
66
let url =
7-
process?.env?.NEXT_PUBLIC_SITE_URL ?? // Set this to your site URL in production env.
8-
process?.env?.NEXT_PUBLIC_VERCEL_URL ?? // Automatically set by Vercel.
9-
'http://localhost:3000/';
7+
(process.env.NEXT_PUBLIC_SITE_URL && process.env.NEXT_PUBLIC_SITE_URL.trim() !== '' ? process.env.NEXT_PUBLIC_SITE_URL :
8+
process.env.NEXT_PUBLIC_VERCEL_URL && process.env.NEXT_PUBLIC_VERCEL_URL.trim() !== '' ? process.env.NEXT_PUBLIC_VERCEL_URL :
9+
'http://localhost:3000/').trim();
10+
1011
// Make sure to include `https://` when not localhost.
1112
url = url.includes('http') ? url : `https://${url}`;
12-
// Make sure to including trailing `/`.
13+
// Make sure to include trailing `/`.
1314
url = url.charAt(url.length - 1) === '/' ? url : `${url}/`;
1415
return url;
1516
};

0 commit comments

Comments
 (0)