'cf' object not being set

It is mentioned in the docs that the cf object would always be available on the request object.

However, my worker sometimes throws an error saying Cannot read property 'country of undefined', where undefined is supposed to be the cf object of the request.

Now, I also have the following page rules set up for that domain (just in case) : IP Geolocation and True client IP header but I still don’t get the cf object on my request.

Any suggestions ?

Really odd, I’d recommend logging the “cf-ray” [request] header (if you don’t already) and support might be able to track down the issue . I’ve never seen this happen but I have a relatively low volume of requests coming in to my workers.

Is every request guaranteed to have a cf.country? Are you just not getting the country field? I would assume that they probably can’t confidently match every IP address to a country.

This makes it seem like the cf object itself isn’t being set

but that might be an issue with CF’s v8 implementation, so i’d agree that you should add a check/test for other properties of cf like colo or httpProtocol.

1 Like