How to call a Worker from another Worker (403)

Inside of a Worker - how do you call another Worker without Cloudflare challenging the request? E.g.
//Worker A
export default {
async fetch(request, env) {
//Worker B
await fetch('https://test.workers.dev');
//^ This throws 403 with a CF challenge
}
}
//Worker A
export default {
async fetch(request, env) {
//Worker B
await fetch('https://test.workers.dev');
//^ This throws 403 with a CF challenge
}
}
I've tried adding a bunch of headers into the Fetch - but still get the 403. Is there a way to tell Cloudflare to trust its own IPs?
4 Replies
AstroDev
AstroDevOP6mo ago
Do you mean RPC?
Chaika
Chaika6mo ago
it doesn't have to be, can just be the fetch handler: https://developers.cloudflare.com/workers/runtime-apis/bindings/service-bindings/
Cloudflare Docs
Service bindings - Runtime APIs · Cloudflare Workers docs
Facilitate Worker-to-Worker communication.
Chaika
Chaika6mo ago
Service Bindings are a smart idea to use anyway if you have control over both workers as they run in same isolate/no network If two workers execute on the same zone (ex: workers.dev is a zone, anything under websites is a zone), they'll never be able to call each other, cookies.me.workers.dev -> cookies2.me.workers.dev = no worker1.cookies.dev -> worker2.cookies.dev = no worker1.cookies.dev-> cookies2.me.workers.dev = yes
AstroDev
AstroDevOP6mo ago
Thanks!
Want results from more Discord servers?
Add your server