Skip to content

Instantly share code, notes, and snippets.

View WillWang2122's full-sized avatar

Robert Black WillWang2122

  • Joined May 2, 2024
View GitHub Profile
@WillWang2122
WillWang2122 / index.js
Created May 4, 2024 05:46 — forked from ihsangan/index.js
Send email from Workers with MailChannel API
async function readRequestBody(request) {
const { headers } = request;
const contentType = headers.get('content-type') || '';
if (contentType.includes('application/json')) {
return JSON.stringify(await request.json());
} else if (contentType.includes('form')) {
const formData = await request.formData();
const body = {};
for (const entry of formData.entries()) {
body[entry[0]] = entry[1];