'geosteering' with workers
herro all. I have a requirement to geosteer requests to a SIP URI depdending on our cx continent location.
I'm not much of a dev... more like a 50 year old infrastructure script kiddie.
Do you think it's just a matter of altering: https://developers.cloudflare.com/workers/examples/country-code-redirect/
to SIP URIs? Something like,
/
* GEO SIP redirector
*
* - Redirect users based on their location to different SIP URIs
/
export default {
async fetch(request) {
/**
* A map of the SIP URIs to redirect to based on country
* @param {Object} countryMap
*/
const countryMap = {
US: "houston2.voip.ms",
EU: "london1.voip.ms",
CA: "houston2.voip.ms"
};
// Use the cf object to obtain the country of the request
const country = request.cf.country;
if (country != null && country in countryMap) {
const sipUri = countryMap[country];
// Remove this logging statement from your final output.
console.log(
Based on ${country}-based request, your user would go to ${sipUri}.
);
return new Response(null, {
status: 302,
headers: {
"Location": sip:${sipUri}
}
});
} else {
// Default redirection if country is not found
return new Response(null, {
status: 302,
headers: {
"Location": "sip:aaa.voip.ms"
}
});
}
},
};
?1 Reply
made this post on a Friday. Just coming back on Monday to see if any of you nerds have done something similar or do you think I am on the right track?