Reflecting user's region

👋 I'm experimenting, and trying to create a worker that simply reflects the requester's region back to them. Like this:

export default {
  async fetch(request, env, ctx) {
    // Get the city and region from the request headers
    const city = request.headers.get('CF-IPCity')
    const region = request.headers.get('CF-IPRegion')

    // Return a response with the city and region
    return new Response(`User's city: ${city}, region: ${region}`, {
        headers: { 'content-type': 'text/plain' },
    })
  },
};


However, I realized that CF-IPCity and CF-IPRegion are only available via enabling this managed transform on a Pages entity (photo attached).

Is there a way to enable a transform like this, but for my worker, rather than a Pages entity?

Thank you in advance! I love working with Cloudflare.
Screenshot_2024-07-08_at_5.26.29_PM.png
Was this page helpful?