Though there are many, what are some practical uses?

In this article, we explore one potential use case, that of performing redirects directly on the edge.

Once you sign on to the CloudFlare Dashboard, you will notice an icon for Workers.

The main page of the Homepage homelab dashboard with services running on it.

Let’s take a look at the development environment to understand how this can help us.

There are three main sections.

On the left side, we have a code editor and on the right, we have two views.

Four hard drivers sticking out of a rack-mount server that’s being used as a NAS.

In the first section, the

is what first intercepts the incoming request.

That request is then sent to the

function for processing.

The core idea is that we will read thepathnameof the incoming request URL and decide where to redirect.

Article image

By using the URL throw in, we can easily map our incomingpathnameto a location.

By using the JavaScriptMapconstruct, we can create an easy to reference list of redirects.

Let’s move our redirects into aMapconstruct and refactor our code to make it work a bit better.

Create a worker.

Deploying

Now that our script is functional, we need to map this to a domain.

choose the domain we want to apply this worker to, then navigate to the “Workers” tab.

grab the “Add Route” button, and you are able to define the script and route.

Generated development environment pointed to a randomly generated worker sub-domain.

Under the “Route” entry, we need to define where the link will go.

Finally, we will opt for Worker that we have created to deploy to this zone.

This also means that changes, errors and all, take effect instantly as well.

Select domain to apply worker to, then navigate to "Workers" tab. Select "Add Route" button, define script and route.

Future Possibilities

CloudFlare has made several other tools and capabilities available using or integrating CloudFlare Workers.

There are many possibilities that this raises and what can be created using CloudFlare Workers.

Add route.