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

Commit 0b7597f

Browse files
Update helpers.ts
Reduced line length and restored chaining operators just in case there's a good reason for including them.
1 parent e679650 commit 0b7597f

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

utils/helpers.ts

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,23 @@ import { Database } from '@/types_db';
33
type Price = Database['public']['Tables']['prices']['Row'];
44

55
export const getURL = () => {
6-
let url =
7-
(process.env.NEXT_PUBLIC_SITE_URL && process.env.NEXT_PUBLIC_SITE_URL.trim() !== '' ? process.env.NEXT_PUBLIC_SITE_URL : // Set this to your site URL in production env.
8-
process.env.NEXT_PUBLIC_VERCEL_URL && process.env.NEXT_PUBLIC_VERCEL_URL.trim() !== '' ? process.env.NEXT_PUBLIC_VERCEL_URL : // Automatically set by Vercel.
9-
'http://localhost:3000/').trim();
6+
// Check if NEXT_PUBLIC_SITE_URL is set and non-empty. Set this to your site URL in production env.
7+
let url = process?.env?.NEXT_PUBLIC_SITE_URL && process.env.NEXT_PUBLIC_SITE_URL.trim() !== ''
8+
? process.env.NEXT_PUBLIC_SITE_URL
9+
: // If not set, check for NEXT_PUBLIC_VERCEL_URL, which is automatically set by Vercel.
10+
process?.env?.NEXT_PUBLIC_VERCEL_URL && process.env.NEXT_PUBLIC_VERCEL_URL.trim() !== ''
11+
? process.env.NEXT_PUBLIC_VERCEL_URL
12+
: // If neither is set, default to localhost for local development.
13+
'http://localhost:3000/';
14+
15+
url = url.trim();
1016

1117
// Make sure to include `https://` when not localhost.
1218
url = url.includes('http') ? url : `https://${url}`;
19+
1320
// Make sure to include trailing `/`.
14-
url = url.charAt(url.length - 1) === '/' ? url : `${url}/`;
21+
url = url.endsWith('/') ? url : `${url}/`;
22+
1523
return url;
1624
};
1725

0 commit comments

Comments
 (0)