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
and CF_API_TOKEN
using Edit Cloudflare Workers
template permissions.
Enable the CodeClimate, Codecov, LGTM, and Synk apps.
(Optionally) Update .nvmrc
:
nvm ls-remote
node -v > .nvmrc
Update wrangler.toml
:
Replace script-name
and script-name-dev
with new-script-name
and new-script-name-dev
respectively.
Add KV Namespaces. For example:
kv-namespaces = [
{ binding = "NAMESPACENAME", id = "86bbce2f10524d33a5f26517e8dee123" }
]
wrangler kv:namespace list
wrangler kv:namespace create NAMESPACENAME
Update account_id
.
Update package.json
:
Replace script-name
with new-script-name
.
Replace repositoryname
with newrepositoryname
.
Update GitHub account name in the following locations:
repository.url
bugs.url
homepage
Update homepage
and author
.
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 with npx 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