Start from scratch
To start from scratch to create a Workers Site, follow these steps:
Ensure you have the latest version of Wrangler and Node.js installed.
In your terminal, run
wrangler generate --site <project-name>
, replacing<project-name>
with the name of your project. The following example creates a project calledmy-site
:$ wrangler generate --site my-site
This command creates the following:
public
: The static assets for your project. By default it contains anindex.html
and afavicon.ico
.workers-site
: The JavaScript for serving your assets. You do not need to edit this but if you want to see how it works or add more functionality to your Worker, you can editworkers-site/index.js
.wrangler.toml
: Your configuration file where you configure your account and project information.
Add your
account_id
to yourwrangler.toml
file. You can find youraccount_id
by logging into the Cloudflare dashboard Account Home > choose your website > Overview > Account ID. For more details on finding youraccount_id
, refer to the Get started guide .You can preview your site by running the
wrangler dev
command:$ wrangler devDecide if you would like to publish your site to a
*.workers.dev
subdomain or a custom domain that you own and have already attached as a Cloudflare zone.Then update yourwrangler.toml
file:*.workers.dev
: Enable theworkers_dev
configuration.workers_dev = trueAnd/Or
Personal Domain: Add your
zone_id
and aroute
.zone_id = "42ef.."route = "https://example.com/*"If you enable
workers_dev
and supply configuration for a personal domain, your Worker will deploy to both locations.Learn more about configuring your project .
Run:
$ wrangler publish