Devallar
Devallar
CDCloudflare Developers
Created by Devallar on 9/22/2023 in #pages-help
Sveltekit + Cloudflare Pages + Resend
Hello! I've been banging my head against a wall as i don't know how to go about finding out whats wrong: I've written a server.js file with a POST that when called sends and email out. It works in local development but once i commit to the git repository and it is deployed on cloudflare pages when i click the button to test send the mail, the console logs a
'{message: 'Internal Error'}message: "Internal Error"[[Prototype]]: Object'
'{message: 'Internal Error'}message: "Internal Error"[[Prototype]]: Object'
along with a
'status code: 500'
'status code: 500'
In addition, i'm using 'svelte-email' which is a port of 'react-email' for sveltekit. Could the problem be there? +server.js
import { json } from '@sveltejs/kit';
import { render } from 'svelte-email';
import { Resend } from 'resend';
import { RESEND_API_KEY } from '$env/static/private';
import MailTemplate from './MailTemplate.svelte';

const resend = new Resend( RESEND_API_KEY );

export const POST = async ({request}) => {
const body = await request.json()
console.log(body);

const {invoiceEmail,invoiceCustomer,invoice} = body;

const html = render({
template: MailTemplate,
props: {
firstName: invoiceCustomer,
invoiceEmail: invoiceEmail,
invoiceCustomer: invoiceCustomer,
invoice:invoice
}
})

try {
resend.emails.send({
from: 'Notifications FOS <[email protected]>',
to: invoiceEmail,
subject: 'Hello '+ invoiceCustomer,
html: html
});
console.log('Email sent successfully');
} catch (error) {
console.log('There was an error sending the mail',error);
}


return json({status:201,message: 'Email sent'})
}
import { json } from '@sveltejs/kit';
import { render } from 'svelte-email';
import { Resend } from 'resend';
import { RESEND_API_KEY } from '$env/static/private';
import MailTemplate from './MailTemplate.svelte';

const resend = new Resend( RESEND_API_KEY );

export const POST = async ({request}) => {
const body = await request.json()
console.log(body);

const {invoiceEmail,invoiceCustomer,invoice} = body;

const html = render({
template: MailTemplate,
props: {
firstName: invoiceCustomer,
invoiceEmail: invoiceEmail,
invoiceCustomer: invoiceCustomer,
invoice:invoice
}
})

try {
resend.emails.send({
from: 'Notifications FOS <[email protected]>',
to: invoiceEmail,
subject: 'Hello '+ invoiceCustomer,
html: html
});
console.log('Email sent successfully');
} catch (error) {
console.log('There was an error sending the mail',error);
}


return json({status:201,message: 'Email sent'})
}
I'm not sure how i can debug this as from the cloudflare pages function tab i get a 500 saying process is not defined. Any ideas?
2 replies