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.
-
(On MacOS with Homebrew:
brew install cloudflare/cloudflare/cloudflared)
Click the button below and follow the setup instructions.
-
Fork repository:
-
Click the
Use this templatebutton. -
Add GitHub Actions secret for
CF_ACCOUNT_IDandCF_API_TOKENusingEdit Cloudflare Workerstemplate 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-nameandscript-name-devwithnew-script-nameandnew-script-name-devrespectively. -
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-namewithnew-script-name. -
Replace
repositorynamewithnewrepositoryname. -
Update GitHub account name in the following locations:
-
repository.url -
bugs.url -
homepage
-
-
Update
homepageandauthor.
-
-
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 lintnpm run lint:fix
-
npm run testnpm run test:clientnpm run test:server
-
npm run deploy
To start a local version:
-
In one terminal window, run
npm run start:client. -
In another, run
npm run startand navigate to http://localhost:8787.
-
/packages/clientis simply a CRA created withnpx create-react-app . --template typescript --use-npm. -
/packages/serveran function which intercepts a request to the client. If it returns a 404, the request is passed through to the client. -
/packages/workerattempts to fetch from the server first, falling back on the client.
* May not be perfect