Can I use a worker for geolocation redirection at the server level?

Can I use this article discussing geolocation data in a worker, so immediately upon connecting to a domain/subdomain, the worker redirects traffic based on geolocation?

But without needing to load an application, so it is as fast as possible, therefore at the server level (apache, nginx) would be great.


That would work for sure, you can either redirect or even change the content dynamically.

Take a look at this reference doc as in Workers there is already a JS object with the country (and possibly more, depending on the plan):

1 Like

Thanks man.

I am a bit of a newbie at all this…

But I don’t even know how to reach the point of handling a request, let alone redirecting traffic. Is there someway I can learn more about where this would be setup in a worker?

Brand new to all this.

Two paths, one is looking at the Workers documentation and, more importantly, learn JS (try and fail, test things, possibly not on production domains).

1 Like

Thanks again!

Looking at this how it works part of the API, it says this is a nodejs environment.

Is that the case then? If so, do I even have access to the system level apache/nginx? Or just the application level nodejs?

It’s not Node.js, it’s V8 based, the same engine that powers Node.js. You can’t access any of the npm modules unless you import them and have the code embedded in the .js file you “upload”. There are build tools to help with this (check their own Wrangler CLI).