Worker using fetch gets 522 from CF Pages Project

Here is my problem. User hits my pages website (origin), the javascript that is loaded hits the pages endpoint /api/data. /api/data internally is bound to a worker so the request is passed through to said worker. That worker runs some business logic then uses await fetch(origin/some-specific-path). That fetch request is returning a 522 from the CF pages project. Running this all locally works fine with the service binding via wrangler. How do I resolve this?
2 Replies
kian
kian15mo ago
https://developers.cloudflare.com/workers/configuration/routing/custom-domains/#worker-to-worker-communication Same-zone subrequests should use Service Bindings, but in this case it sounds like you might as well just be using Functions rather than a separate Worker. You're hitting a 522 since there is no origin to hit, you're going past the Pages Worker & hitting a non-existent origin (as per the documentation).
kingmesal
kingmesalOP15mo ago
My pages function (A) has a function binding to the worker (B) for the specific endpoint. Worker (B) calls for a resource (html file not an endpoint) on the pages project (not endpoint A) Now to be clear, the pages project is on a custom domain and the worker on .dev
Want results from more Discord servers?
Add your server