You will also need theWorkers Bundled plan, which offers the KV feature.

The following features are available and where they differentiate from the free plan.

Wrangler Command-Line Tool

To create a site deployment, CloudFlare has created theWrangler command-line tool.

Tuya Wi-Fi IR Blaster on a wooden desk.

Wrangler requires installation via eitherNPM (NodeJS package manager)orCargo (Rust language package manager).

This will decrease the installation size.

In this example, we are using the1.11.0version of Wrangler, which introduced a newer and easier authentication method.

Article image

Wrangler Login and Site Creation

First, we are going to login to CloudFlare using Wrangler.

To do this, we use the newwrangler loginfeature.

Otherwise, sign in and Wrangler will configure the API token automatically.

Wrangler login feature

Generating the Site

Next, we will generate the site itself.

Utilizing thegeneratecommand, we will quickly create the site.

This is an optional step but highly recommended.

Log in and Wrangler will configure the API token automatically

At a minimum, you will need to add theaccount_idvalue within thewrangler.tomlfile to preview the site.

Openwrangler.tomland update theaccount_idvalue to your CloudFlare accounts value.

Deploying the Site to Production

The next step would be to deploy this site to production.

Navigate into the site directory and create a new repository via git init

There are only a small handful of configurations that need to be tweaked in thewrangler.tomlfile.

Conclusion

CloudFlare Workers Sites offer powerful functionality with easy developer access.

Static sites are incredibly fast and secure due to the lack of interactivity.

Retrieve Account ID by navigating to CloudFlare dashboard, click on Workers, locate Account ID.

Open wrangler.toml, update account_id value to CloudFlare accounts value.

Use preview command from Wrangler to generate and display the site within the browser. Adding the –watch parameter, any changes made are immediately reflected

Use preview command from Wrangler to generate and display the site within the browser.

Retrieve the zone_id by navigating to website you want to apply Worker to within CloudFlare dashboard, going to Overview page, and finding Zone ID under API section.

Run publish command to make site public and create Workers Site under the zone and route defined.