Show Javascript Challange to everyone except 2 countries

Hello Sir,

My Question is about firewall rule, I want to show JavaScript challenge to all users except users for Two countries.

Can Anyone help me in doing it.

Thank You

Well I don’t know about using the firewall, but you could easily solve that using a worker.

All requests to workers have a cf object with info on the country of request.

Something like this:

addEventListener('fetch', event => {
  event.respondWith(checkCountry(event))
});

async function checkCountry (event) {
  const country = event.request.cf.country;

  if (country === 'US') {
    return new Response.redirect('https://google.com', 301);
  } else {
    return await fetch('https://somedomain.com/javascript-challenge');
  }
}

Try this:

2 Likes

This topic was automatically closed after 30 days. New replies are no longer allowed.