Explicitly choosing worker location to perform request based on path

Hi, I have two questions pls.

  1. Is it possible to match a URL path to a specific Cloudflare Worker location. For instance, if URL matches /new-zealand/* > then force the worker in New Zealand to perform the work. (Even though the request may originate from USA etc)

  2. Is it possible to run cURL requests from Cloudflare workers

Thanks very much,
Richard

You can not choose the location of the worker

You use the fetch API to make HTTP requests

1 Like

You can’t force which POP will receive the inbound request, but once the request hits the Worker you can force it to be routed to a specific Cloudflare COLO for processing by another Worker in that location. The routing logic cannot be done with the defined Worker Routes but rather needs to be handled with your own logic inside the Worker for making sub-requests to which specific COLO you want to send the sub-requests to.

Can you tell me more about your use case for this?

Thanks for that, appreciate it. :+1:

Ok so request hits worker > then I can force reroute to a specific COLO for processing by another worker.

I couldn’t find in the docs anywhere how to force reroute to specific COLO from inside a worker. Is there an example somewhere?

This use case is to check time to first byte from a specified location. For example, I want to measure the TTFB (using code inside of worker) from New Zealand and then from USA etc.

Thanks for your help so far too.

Theres no documentation about how to do this and I’m not sure if its allowed to be done. Pending a bug report.

Great use case for this hack. You could make one API request in your program which hits the closest POP, that Worker then fires off a sub-request to each COLO you want to test from which essentially runs another instance of the Worker at those locations where you can execute the TTFB test and return the response back up the request chain.

I have a private example pending a bug report to security concerns enabled by this hack. I don’t think this forced COLO execution is a bug itself but it makes possible some other things you wouldn’t usually be able to do.

All the clues are in the documentation if you want to figure it out yourself. I’d be happy to share privately.

Yes it seems like an ideal use case… Pity you can specify the region without the hack you mentioned.

By all means, yes pls share privately if you would. Otherwise might be easier to stick with a standard proxy solution…

Ok, give me a contact and I’ll send you a demo and some data for each each of the COLO routes.

Ok great, thanks. Just send it to (redacted do not share pii)

Cheers

Details sent to your email. I also included a link to my video demo on YouTube.

Let me know how you go with implementing this.

Thanks very much, appreciate it.

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.