Hello, I’m using the countrycode redirect, based on this example: https://developers.cloudflare.com/workers/examples/country-code-redirect
all works, but I need also to modify the workers to change the visibility of some parts of the website.
in html I have this:
<h1 id=pricetag class="label">one gazillion dollars</h1>
I need to hide when the visitors came from a specific country, instead of doing the redirect.
code of workers:
addEventListener('fetch', event => {
event.respondWith(handleRequest(event.request))
})
/**
* Returns a redirect determined by the country code
* @param {Request} request
*/
async function redirect(request) {
// Use the cf object to obtain the country of the request
// more on the cf object:
const country = request.cf.country
if (country != null && country in countryMap) {
const url = countryMap[country]
return Response.redirect(url)
}
else {
return await fetch(request)
}
}
/**
* A map of the URLs to redirect to
* @param {Object} countryMap
*/
const countryMap = {
EU: "https://baltaco.com/",
DE: "https://silcomnorth.com/",
}
async function handleRequest(request) {
return redirect(request)
}
addEventListener("fetch", event => {
event.respondWith(handleRequest(event.request))
})
Some suggestion?
thanks