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' },
})
},
};
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.
No description
2 Replies
kian
kian•5mo ago
They should be available as request.cf.city and request.cf.region, no need for headers
stevent
steventOP•5mo ago
no wayyyyyyyyy thank you God i love cloudflare. Have a good one!
Want results from more Discord servers?
Add your server