Update index.js

This commit is contained in:
2025-12-03 14:20:54 -08:00
committed by GitHub
parent 26834e0c2c
commit 6bd02588aa

View File

@@ -1 +1,33 @@
export default {
async fetch(request) {
const url = new URL(request.url);
// Forward path to Resend (e.g. /emails/batch)
const target = 'https://api.resend.com' + url.pathname + url.search;
// Handle Preflight (Browser checks permissions first)
if (request.method === "OPTIONS") {
return new Response(null, {
headers: {
"Access-Control-Allow-Origin": "*",
"Access-Control-Allow-Methods": "GET, POST, OPTIONS",
"Access-Control-Allow-Headers": "Content-Type, Authorization",
},
});
}
// Forward the actual request
const res = await fetch(target, {
method: request.method,
headers: request.headers,
body: request.body
});
// Return response with CORS headers allowed
const newHeaders = new Headers(res.headers);
newHeaders.set("Access-Control-Allow-Origin", "*");
return new Response(res.body, {
status: res.status,
headers: newHeaders
});
}
}