Skip to content

Commit 4909dfe

Browse files
committed
fix: Netlify env var access
1 parent bcb13c4 commit 4909dfe

2 files changed

Lines changed: 9 additions & 1 deletion

File tree

index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<meta name="theme-color" content="#673AB8">
1010
<link rel="alternate" type="application/rss+xml" href="https://preactjs.com/feed.xml">
1111
<link rel="alternate" type="application/atom+xml" href="https://preactjs.com/feed.atom">
12-
<meta property="og:image" content="%DEPLOY_URL%/og-image.png">
12+
<meta property="og:image" content="%NETLIFY_DEPLOY_URL%/og-image.png">
1313
<meta name="twitter:card" content="summary">
1414
<link href="https://cdn.jsdelivr.net" rel="preconnect" crossorigin="anonymous">
1515
</head>

plugins/netlify.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,14 @@ export function netlifyPlugin() {
4545
},
4646
configurePreviewServer(server) {
4747
server.middlewares.use(netlifyFunctionMiddleware);
48+
},
49+
// Vite only accesses env vars prepeneded with 'VITE_', so this
50+
// is the simplest way to access Netlify's env vars.
51+
transformIndexHtml(html) {
52+
return html.replace(
53+
'%NETLIFY_DEPLOY_URL%',
54+
process.env.DEPLOY_URL || ''
55+
);
4856
}
4957
};
5058
}

0 commit comments

Comments
 (0)