A perfect* template for a Cloudflare Workers project, using Workers Sites (React although can be easily swapped for Gatsby or another static builder), TypeScript, Jest and Prettier.
And now, with end-to-end tests thanks to the new wrangler dev
command and Playwright! ✨
-
(On MacOS with Homebrew:
brew install cloudflare/cloudflare/cloudflared
)
Click the button below and follow the setup instructions.
-
Fork repository:
-
Click the
Use this template
button. -
Add GitHub Actions secret for
CF_ACCOUNT_ID
andCF_API_TOKEN
usingEdit Cloudflare Workers
template permissions. -
Enable the CodeClimate, Codecov, LGTM, and Synk apps.
-
-
(Optionally) Update
.nvmrc
:- Find available versions with
nvm ls-remote
- Use the current Node.js version with
node -v > .nvmrc
- Find available versions with
-
Update
wrangler.toml
:-
Replace
script-name
andscript-name-dev
withnew-script-name
andnew-script-name-dev
respectively. -
Add KV Namespaces. For example:
kv-namespaces = [ { binding = "NAMESPACENAME", id = "86bbce2f10524d33a5f26517e8dee123" } ]
- Find existing namespaces with
wrangler kv:namespace list
- Create a new namespace with
wrangler kv:namespace create NAMESPACENAME
- Find existing namespaces with
-
Update
account_id
.
-
-
Update
package.json
:-
Replace
script-name
withnew-script-name
. -
Replace
repositoryname
withnewrepositoryname
. -
Update GitHub account name in the following locations:
-
repository.url
-
bugs.url
-
homepage
-
-
Update
homepage
andauthor
.
-
-
npm i
-
(Optionally) Update npm packages:
npm run updatePackages
-
Update
README.md
, (don't forget the badges!). -
Follow additional instructions in
/packages/*/README.md
These should all be self-explanatory:
-
npm run lint
npm run lint:fix
-
npm run test
npm run test:client
npm run test:server
npm run test:e2e
-
npm run deploy
To start a local version:
-
In one terminal window, run
npm run start:client
. -
In another, run
npm run start
and navigate to http://localhost:8787.
-
/packages/client
is simply a CRA created withnpx create-react-app . --template typescript --use-npm
. -
/packages/server
an function which intercepts a request to the client. If it returns a 404, the request is passed through to the client. -
/packages/worker
attempts to fetch from the server first, falling back on the client. -
/packages/e2e
runs end-to-end tests on the full-stack Worker.
* May not be perfect