@designsystemsinternational/cloudflare
v0.2.3
Published
This package provides a set of helpers to deploy (static) websites to Cloudflare Workers. It comes with a nice set of tools:
Keywords
Readme
DSI Cloudflare Package
This package provides a set of helpers to deploy (static) websites to Cloudflare Workers. It comes with a nice set of tools:
- A CLI to set up the deployment config (including
wrangler.jsonc) for a repo - A Cloudflare Worker to password protect a static website
- A Vite application that builds the auth templates needed for the password worker
Usage
Setting up a new deployment
In order to deploy a new site on Cloudflare Worker, run the following:
npx @designsystemsinternational/cloudflareThe CLI will guide you through setting up the deployment, including with password protection.
Development
File structure
The repo is divided into these main folders:
templates/holds a Vite app that can be used to make frontend templates. It currently just renders the auth templates.workers/holds all Cloudflare Workers code. It currently just has apasswordworker that renders the auth templates in front of a static site.cliholds the code for the npx command
Local development
Because of the way Cloudflare workers operate, it's hard to have a single local development command to test the entire flow while preserving the Vite hot module reloading. So, the development will need to happen in two ways:
- To design the auth templates, run
cd templates && npm run devto run the Vite dev server inside the/templatesfolder. This will enable hot module reloading, but the worker auth script won't run, so the actual login process won't work. - To test the whole flow, run
npm run devin the root folder. This runs the cloudflare worker in a local environment that matches the production environment. With this, you can test the entire login flow, but the auth templates will usevite buildand not run via hot module reloading.
All you need is to add a .env.local file with the following environment
variables:
SECRET=secret
PASSWORD=yiahFor testing the CLI, I currently just create a new test package alongside this
folder and run npx ../cloudflare.
TODO
- Figure out needs for deploying static websites
