Possible to get PoP running worker code?


I just started using workers a couple of days ago to do some load balancing and failover depending on region of the request. This works great as I can send traffic from APAC to Sydney and everyone else (for the moment) to New York, with the potential to expand to other locations, such as Europe, as required.

While I was writing the worker I thought about how I can find out which location to send the user to, currently I am using the cf-ipcountry header and matching that up to country.io data for continents.

This works, but is lacking a bit of granularity, for example I can’t differentiate if someone is on the west or east coast of the USA and send them to a closer server (NY vs SF)

Would it be possible for workers to gain the ability to know which PoP they are being executed from (maybe some sort of environment variable that could be accessed?)
This would make workers even more powerful!

Just a quick note: I can’t use DNS load balancing because I only want/need load balancing on specific routes currently (cost saving mainly)

On the surface this sounds quite simple, but I am sure workers are much more complex under the hood :stuck_out_tongue:


Bump :man_shrugging:

Hi @user4562,

Sorry for the long delay in replying! We have actually added this information to the event.request.cf object in the meantime. You can see our documentation on it here: Request · Cloudflare Workers docs

In short, event.request.cf.colo is a string that is the IATA airport code representing the PoP that request is executing in.


1 Like


That is great news, thanks a lot!

Unfortunately while I am testing it the event.request.cf object is undefined, I have also tried it at Cloudflareworkers.com.
Is it not fully live yet?


Try on the live environment, on the preview it often seems like those variables (it’s a different server than live code) are null.


Hey, is there any way to get this info from the CRON scheduled instances?

The scheduled event seems to have only type and timestamp