Longshot - Any chance you guys could provide location headers?

Some services like Fastly or Cloud Front are able to provide city based headers. I know there’s nothing in the docs about it, but does one of your upstream providers (like DNS routing) provide any of this info?

Happy to share my use case if you’d like.

1 Like

Right now, we only give you the region the request came through (FLY_REGION header). We don’t have any quick way to do geo ip lookups, the licensing for most of those tools won’t let us include them in requests. There are probably free libraries for your runtime though! This one for Node looks pretty decent: https://github.com/geoip-lite/node-geoip

Thanks for the response! Maxmind is a little inaccurate for what I need but getting a good source of data is not easy.

@austincollinpena I have been looking into this too. I haven’t tried it, but one possible solution may be to proxy the request through a Cloudflare worker. Doing so shouldn’t add much to the latency as they run all over the world. It seems you then get access to all the location data you could want: city, country, continent etc, added by them:

See https://developers.cloudflare.com/workers/runtime-apis/request#incomingrequestcfproperties

You’re a life saver. Thank you Greg!

However I need to have a multitenant application and would need their subdomains for SaaS. I’ll look into that as an option for the future.

Unless you see a way around having TLS termination on their end?

You’re welcome.

Hmm … not sure. From what I can see, they provide SSL as part of their proxy and so you are then free to make whatever subrequest you need in the worker. Like on https://developers.cloudflare.com/workers/examples/bulk-origin-proxy it gives an example of using multiple origins. And so in theory you could look at the requested domain and pick the one to use. But … if they have a paid product for that, I’m guessing workers won’t let you bypass using that :frowning:

Doing custom domains with them is uber expensive.

How precise are you trying to get?

@greg For that to work I need to have all the connecting domains proxied through Cloudflare.

@kurt I’m only going to offer city level customization if I can get 95%+ for most cases. Providers like Akamai, Fastly, and others with DNS level data hit those numbers. However, you need to use them as your actual provider to get that data.

Are you ok with changing the application design to make separate calls to get the location? I built blip.runway7.net for that. Running a separate location echo API helps a bit if you’re willing to change your request flow.

If you want headers only without separate calls, and you have a lot of custom domains, I’d consider one Cloudfront distribution per customer and domain. The CF units are free, and it’s possible to create them off the API. And you’ll get the headers as well. And free SSL for each domain.

Thanks for the advice @sudhir.j, I think I’ll do that.

If I’m not mistaken, Wildcard proxy for everyone should now allow to use Cloudflare with a Worker to add those headers, similar to what @sudhir.j mentioned.

I’m currently rethinking our setup to maybe use machines and cloudflare/cloudfront in front as a gateway for various functionalities and especially also location information.

Edit: Actually thinking again this (cloudflare) should work for subdomains, I’m not sure about user domains though :thinking:

You’re in luck?

You don’t need use Workers here, instead connect Cloudflare to your origin on Fly over cloudflared? Probably faster that way.

1 Like

Any news on fly location headers by any chance? :innocent:

1 Like

@CanRau I believe you still need to put some form of proxy in front of your app. To avoid adding a per-request cost, you could use a CDN that does not charge per-request. For example Cloudflare, Stackpath, Bunny … Each has its own trade-off though.

1 Like

According to their docs, Cloudflare uses the maxmind database for its geolocation headers.

Benefit of using the database directly is that you avoid additional roundtrips for each incoming request.

While their database comes with a subscription, they also have a free offering: GeoLite2.

If you can get away with less accuracy, and don’t mind managing database updates yourself, this might be a decent solution. It is at least the solution I am planing to use when moving some things to fly.io that rely on such a geolocation header.