Email Worker to webhook POST fetch not working in production

Hello, I am trying to send a POST request to a webhook after receiving e-mails, using a Worker. This works in the edit environment; the webhook receives the POST request successfully. But as soon as I publish it live and send an e-mail to it, it doesn't do anything and it tells me Delivery Failed. I have looked at <#1185774979082637432>, and am doing the same approach. (The forward does work though if RegEx is not matched.) Here's some screenshots:
No description
No description
7 Replies
Erisa
Erisa4mo ago
Can you stream the worker logs while reproducing? Should show he actual error
Eli
EliOP4mo ago
(how do i actually do that :) Nvm I think I found it at Real time logs
"exceptions": [
{
"name": "TypeError",
"message": "A request with a one-time-use body (it was initialized from a stream, not a buffer) encountered a redirect requiring the body to be retransmitted. To avoid this error in the future, construct this request from a buffer-like body initializer.",
"timestamp": 1723663558233
}
],
"exceptions": [
{
"name": "TypeError",
"message": "A request with a one-time-use body (it was initialized from a stream, not a buffer) encountered a redirect requiring the body to be retransmitted. To avoid this error in the future, construct this request from a buffer-like body initializer.",
"timestamp": 1723663558233
}
],
Chinese to me tbh i think it doesn't like message.raw, how do i handle it properly? If I transfer message.raw to not be a stream, i get "Too many redirects.", even tho I don't receive any incoming requests on the webhook and don't have any redirects configured anywhere. (And it also simply works in the test environment, but doesn't in production.)
"exceptions": [
{
"name": "TypeError",
"message": "Too many redirects.",
"timestamp": 1723667379942
}
],
"exceptions": [
{
"name": "TypeError",
"message": "Too many redirects.",
"timestamp": 1723667379942
}
],
export default {
async email(message, env, ctx) {
let arrayBuffer = await new Response(message.raw).arrayBuffer()
await fetch('https://some.url/post', {
body: arrayBuffer,
method: 'POST',
headers: {
'email-to': message.to,
'email-from': message.from,
'Authorization': env.AUTH
}
})
}
}
export default {
async email(message, env, ctx) {
let arrayBuffer = await new Response(message.raw).arrayBuffer()
await fetch('https://some.url/post', {
body: arrayBuffer,
method: 'POST',
headers: {
'email-to': message.to,
'email-from': message.from,
'Authorization': env.AUTH
}
})
}
}
Got this atm. Been trying to get it to work all day, I just can't seem to. Works in test env, doesn't in production: Too many redirects I’m still having this issue. Does someone have an idea?
Chaika
Chaika4mo ago
On the zone you have the email worker attached to, go to ssl/tls -> overview and switch from Flexible to Full (Strict) Magic link: https://dash.cloudflare.com/?to=/:account/:zone/ssl-tls/
Eli
EliOP4mo ago
That worked, thank you so much!
Chaika
Chaika4mo ago
Sure, the "magic" is that all outgoing fetch requests from your worker "running" on your zone/website go through your zone's configuration, with "Flexible" they were being downgraded to http:// (even though you specified https://) and being infinitely redirected
ksnll
ksnll4mo ago
Thanks, got into the same issue and spent several hour debugging it.. finally got it working thanks to the "strict" setting!
SC8
SC83mo ago
THANK YOU - I lost a day on this as well @Chaika THANK YOU - maybe this could make it's way into the documentation
Want results from more Discord servers?
Add your server