export default { async fetch(request) { /** * A map of the URLs to redirect to * @pa

export default {
async fetch(request) {
/**
  • A map of the URLs to redirect to
  • @param {Object} countryMap*/const countryMap = {BA: "https://example.com/us",HR: "https://example.com/eu",};// Use the cf object to obtain the country of the request// more on the cf object: https://developers.cloudflare.com/workers/runtime-apis/request#incomingrequestcfpropertiesconst country = request.cf.country;if (country != null && country in countryMap) {const url = countryMap[country];return Response.redirect(url);} else {return fetch(request);}},};
The Request interface represents an HTTP request and is part of the Fetch API.
Was this page helpful?