Pass ExecutionContext through the email processing chain so notifySubscribers is called via ctx.waitUntil after a new email is stored. Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
23 lines
734 B
TypeScript
23 lines
734 B
TypeScript
import { Context } from "hono";
|
|
import { Env } from "../types";
|
|
import { ForwardEmailPayload, handleForwardEmail } from "../lib/forwardemail";
|
|
|
|
export async function handle(c: Context): Promise<Response> {
|
|
try {
|
|
const env = c.env as unknown as Env;
|
|
const payload: ForwardEmailPayload = await c.req.json();
|
|
|
|
console.log("Received email:", {
|
|
to: payload.recipients?.[0],
|
|
from: payload.from?.text || "Unknown",
|
|
subject: payload.subject,
|
|
contentType: payload.html ? "HTML" : "Text",
|
|
});
|
|
|
|
return handleForwardEmail(payload, env, c.executionCtx);
|
|
} catch (error) {
|
|
console.error("Error processing email:", error);
|
|
return new Response("Error processing email", { status: 500 });
|
|
}
|
|
}
|