Skip to content

Commit 961cd7e

Browse files
committed
use vite's import.meta.env instead of process.env
1 parent 38715fd commit 961cd7e

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

src/constants/site-config.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
const buildMode = process.env.BUILD_ENV || "production";
1+
const buildMode = import.meta.env.BUILD_ENV || "production";
22
const siteUrl = (() => {
3-
let siteUrl = process.env.SITE_URL || process.env.VERCEL_URL || "";
3+
let siteUrl = import.meta.env.SITE_URL || import.meta.env.VERCEL_URL || "";
44

55
if (siteUrl && !siteUrl.startsWith("http")) siteUrl = `https://${siteUrl}`;
66

src/utils/get-picture.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,10 @@ function getSupportedWidth(width: number) {
4343

4444
const isDev = Boolean(import.meta.env?.DEV);
4545

46-
const cloudName = process.env.PUBLIC_CLOUDINARY_CLOUD_NAME;
47-
if (!isDev && !cloudName)
46+
const PUBLIC_CLOUDINARY_CLOUD_NAME = import.meta.env
47+
.PUBLIC_CLOUDINARY_CLOUD_NAME;
48+
49+
if (!isDev && !PUBLIC_CLOUDINARY_CLOUD_NAME)
4850
console.error("missing public variable CLOUDINARY_CLOUD_NAME");
4951

5052
function getSource(src: string, width: number, getFormat: string) {
@@ -58,7 +60,7 @@ function getSource(src: string, width: number, getFormat: string) {
5860
} else {
5961
// If in production use cloudinary's fetch
6062
const domainUrl = new URL(src, siteUrl);
61-
return `https://res.cloudinary.com/${cloudName}/image/fetch/w_${width},f_${getFormat},q_auto/${encodeURIComponent(domainUrl.toString())}`;
63+
return `https://res.cloudinary.com/${PUBLIC_CLOUDINARY_CLOUD_NAME}/image/fetch/w_${width},f_${getFormat},q_auto/${encodeURIComponent(domainUrl.toString())}`;
6264
}
6365
}
6466

0 commit comments

Comments
 (0)