Enable CF-IPCountry in online editor

The following returns the current country code:

addEventListener("fetch", event => {

async function handleRequest(request) {
   const country = request.headers.get('CF-IPCountry')
   return new Response(`Hello world ${country}`)

It works on on a live site.
It works on the Workers Playground online app.
It doesn’t work in the Cloudflare Online editor. It returns null.

So my question:
Is it possible to enable country detection (the CF-IPCountry header) in the online Workers editor?


The editor doesn’t go through the CF system as everything else does therefore no, these headers don’t exist. You could manually add them but of course that isn’t ideal.

I’d suggest using Wrangler and Miniflare to test locally and have those headers.

1 Like

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