/** E2E 临时接收器:18790,打印签名/Authorization 校验结果 */ const KEY = "wmh_e2e_key_12345"; Bun.serve({ port: 18790, async fetch(req) { if (req.method === "GET" && new URL(req.url).pathname === "/__stats") { return Response.json({ ok: true, note: "see stdout for deliveries" }); } if (req.method !== "POST" || new URL(req.url).pathname !== "/hook") { return Response.json({ error: "not found" }, { status: 404 }); } const body = await req.text(); const ts = req.headers.get("X-WmailHub-Timestamp") ?? ""; const sig = req.headers.get("X-WmailHub-Signature") ?? ""; const { hmacSha256Hex } = await import("../../shared/src/index.ts"); const expect = await hmacSha256Hex(KEY, `${ts}.${body}`); const payload = JSON.parse(body) as Record; console.log( JSON.stringify({ got: "webhook", auth: req.headers.get("Authorization"), signature_valid: sig === expect, event: payload.event, subject: payload.subject, mailbox: payload.mailbox, custom_header: req.headers.get("X-Custom"), }), ); return Response.json({ ok: true }); }, }); console.log("receiver on :18790");