I have a hopefully easy one. We're using Cloudflare to front our websites, but just for DNS - so we

I have a hopefully easy one. We're using Cloudflare to front our websites, but just for DNS - so we have www-staging.foo.com that is controlled by Cloudflare, and we're using a CNAME to staging.actual-origin.com let's say, and it is WordPress but not sure that matters but naturally it's expecting requests from www-staging.foo.com in terms of the host.

All well and good, that works fine, now what we want to do is have a worker route intercept some traffic and set some additional headers on the response. I thought this would be pretty simple - have a worker route for /the-page-to-intercept with a Worker, call await fetch(request) to hit the origin, and then modify the response before returning it from the worker (creating a new response really).

However, what's actually happening is downstream (staging.actual-origin.com) is returning an error that suggests the host isn't being sent through - if I hit the downstream URL in the browser I get the same error (the error is site not found, effectively). Is this just some quirk of CNAMEs where it's not correctly hitting the origin, and is there any way to fix this / am I doing something dumb? I thought about setting the host header but that's not allowed with the Fetch API pretty sure
Was this page helpful?