I added a Response Headed with the ip.src.city, but i cant read it on the client side javacript?
I belive headers are not readable in JS in the browser unless another request is made right? But I can read document.cookie, so how can i set a dynamic cookie with the ip.src.region?
set-cookie but what is the expression in the transform ? country=ip.src.region does not work.
I am using Cloudflare pages and transforms.
4 Replies
I think it would be smarter to just fetch a static url that has certain headers on it with a transform rule instead of going the cookie route, but if you insist:
concat("city=", ip.src.city)
Hi, you mention i should send a new fetch request, but i feel that the data that i need is already in the header when the first page loads in the browser, i just can read it from javascript. it doesn't seem to be performant to make antoher roundtrip to the server to obtain data that is already in the header in the initial request. - but i would like to hear you out on what would be best.
concat("city=", ip.src.city) , can i concat the region and country too? ip.src.region , ip.src.country.. tried this, but it wouldn't save
that's because you're missing commas, but you can't use Set-Cookie header like that. You'd need multiple set-cookie headers, and transform rules simply don't support that right now
i see, so what i would need to do is to make another fetch call to a worker and get the ip details from there , something i wanted to avoid as there is a delay.