NextJS worker cannot call another worker
Cloudflare Workers do not allow communication between my Workers via HTTP requests within the same domain. I found two possible solutions:
However, tragedy struck. Requests from www.mydomain.io to api.mydomain.io failed. The backend didn’t receive anything, and the frontend got error code 522. Could it be that Cloudflare has some default rule that prevents this setup? I am completely lost at this point. Does anyone have any advice on how to resolve this?
- Use service bindings.
- Use different subdomains.
I gave up on option 1 because I couldn’t find a way to access the Cloudflare env. Most of the tutorials focus on how one Worker server calls another, where there’s always a fetch entry point injected into the env. However, Next.js Workers don’t seem to work this way. I found some examples suggesting that you can install a custom entry point on the page to potentially access the env, but since my Next.js is deployed on Workers, I couldn’t find any relevant resources. Eventually, I gave up on this path.
However, tragedy struck. Requests from www.mydomain.io to api.mydomain.io failed. The backend didn’t receive anything, and the frontend got error code 522. Could it be that Cloudflare has some default rule that prevents this setup? I am completely lost at this point. Does anyone have any advice on how to resolve this?