Is a worker allowed to make requests to another worker?

I’m trying to setup a “catch-all” worker which acts in a similar way to a reverse proxy by looking at the URL path that’s been requested and then requesting content from a predefined application running on another worker within the same workers.dev subdomain. Reason is so the “catch-all” worker can apply consistent http headers, navigation and footer elements while requesting dynamic content from the appropriate web app on the other workers.

There isn’t an “origin” as such because everything will be served from workers. Also each webappx.subdomain.workers.dev worker looks for a special http header applied by the router. Any requests without the special header are dropped. This prevents a visitor from browsing directly to the webapps.

Is this setup possible with Cloudflare? I seem to have read that one worker cannot call another within the same workers.dev subdomain which seems very limiting and would make this architecture impossible without lots of different domains.

architecture

You can’t call another Worker in the same zone, be it workers.dev (not sure if it’s per subdomain or the whole thing) or your own, but…

You can call other domains’ Workers. So this structure can be done with a worker on a domain you own (or on the workers.dev subdomain) and then call the other via their workers.dev URL (or on another domain you own). The important thing is that each layer is on a different domain from the previous, but you can simply alternate between two, example.com and example.workers.dev.

1 Like