Skip to content

Commit b98eff5

Browse files
committed
fix: use nodejs_compat_v2 and useRuntimeConfig for Cloudflare Pages
Switch to nodejs_compat_v2 flag to avoid unenv process polyfill crash and replace process.env with useRuntimeConfig() in the contact handler.
1 parent 9c673ba commit b98eff5

3 files changed

Lines changed: 8 additions & 4 deletions

File tree

nuxt.config.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,10 @@ export default defineNuxtConfig({
9393
provider: 'none',
9494
},
9595

96+
runtimeConfig: {
97+
resendApiKey: '',
98+
},
99+
96100
nitro: {
97101
preset: 'cloudflare-pages',
98102
rollupConfig: {

server/api/contact.post.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@ export default defineEventHandler(async (event) => {
1010
throw createError({ statusCode: 400, statusMessage: 'Invalid email address' })
1111
}
1212

13-
const apiKey = process.env.RESEND_API_KEY
14-
if (!apiKey) {
13+
const { resendApiKey } = useRuntimeConfig()
14+
if (!resendApiKey) {
1515
throw createError({ statusCode: 500, statusMessage: 'Email service not configured' })
1616
}
1717

1818
try {
19-
const resend = new Resend(apiKey)
19+
const resend = new Resend(resendApiKey)
2020
await resend.emails.send({
2121
from: 'Portfolio Contact <noreply@arckiejadulco.dev>',
2222
to: 'arckie.jadulco@gmail.com',

wrangler.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
name = "portfolio-website"
22
pages_build_output_dir = "dist"
33
compatibility_date = "2024-12-01"
4-
compatibility_flags = ["nodejs_compat"]
4+
compatibility_flags = ["nodejs_compat_v2"]

0 commit comments

Comments
 (0)