Possible to get PoP running worker code?

workers

#1

Hi,

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:

Thanks


#2

Bump :man_shrugging:


#3

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: https://developers.cloudflare.com/workers/reference/request-attributes/

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

Harris


#4

Hi,

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?

Thanks


#5

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