If you’ve ever tried to have two Cloudflare Workers call each other (e.g., Worker A → Worker B → Worker A, or even just Worker A calling Worker B on the same zone), you’ve probably hit the dreaded Error 1042:
Worker tried to fetch from another Worker on the same domain, which is disallowed for security reasons.This restriction exists to prevent infinite request loops and potential abuse, but sometimes you legitimately need one Worker to fetch from another (microservices-style architecture, shared logic, etc.).
The Fix: Enable the global_fetch_strictly_public Compatibility Flag
Cloudflare provides an opt-in flag that relaxes this restriction and allows Workers to fetch each other as long as the request goes to a public hostname (i.e., your custom domain or *.pages.dev, not a workers.dev subdomain that is private).
Step-by-step:
- Log into the Cloudflare dashboard.
- Go to Workers & Pages → select your Worker → Settings → Runtime.
- Scroll down to Compatibility flags.
- Add the flag: global_fetch_strictly_public
- Click Deploy (or Save & Deploy).
Do this for both Workers (the one making the request and the one being requested).
That’s it!
Important Notes
- The flag only allows fetches to public hostnames. Example that works: fetch("https://api.yourdomain.com/some-path") Example that still fails: fetch("https://my-worker.my-subdomain.workers.dev") if that workers.dev URL is not public.
- Always use your custom domain (or a public *.pages.dev) for inter-Worker communication after enabling the flag.
- Reference: Cloudflare Docs – global_fetch_strictly_public
Once the flag is enabled on both sides, your Worker-to-Worker fetches will work without Error 1042.
Happy building! 🚀