Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to tell if a request is coming from Scotland?

The title might seem a bit odd, but I have a situation where I have a web application (Node.js application served up behind Azure Frontdoor + Azure App Service) and need to know if a request has come from Scotland, so that I can show some specific assets (mostly images) to the user in place of the default ones.

I was hoping to do this programmatically, leveraging Frontdoor's capabilities to inject something into the request coming into App Service and then checking the header in my Node.js application and decide what assets to load that way.

However, Frontdoor will only tell me if a request originated in the United Kingdom. I've also looked at a few libraries/APIs and nothing seems to be that granular. I've also tried looking up if there is a canonical list of IP ranges within Scotland, but that (expectedly) turned up nothing.

I know this problem could be solved with a UX change (i.e. asking someone at the beginning of their journey where they reside) but was hoping to make things slightly more seamless.

Any suggestions would be appreciated.

like image 557
Dave Cooper Avatar asked Oct 30 '25 09:10

Dave Cooper


1 Answers

You could use a service like https://ipinfo.io/ it has an IP Geolocation API.

You can get the user IP in the header X-Azure-ClientIP from Frontdoor and then make an API call to get the region. Furthermore, you should link that information to a user for persistence you won't have to make an API call every time a user access your website.

Example IP information from Scotland

like image 126
Lauden Avatar answered Nov 01 '25 10:11

Lauden



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!