Cloudflare Worker Deployment: Wrangler CLI
Wrangler is Cloudflare's official CLI tool for developing and deploying Workers.
Prerequisites for Wrangler CLI Deployment
Before proceeding with Wrangler CLI deployment, ensure you have the following:
- Node.js: Version 22 or later recommended. You can download it from nodejs.org.
- npm: Version 9 or later. This usually comes bundled with Node.js.
- Git: A local Git client for cloning repositories.
- pnpm: This project uses pnpm for package management. If you don't have it, install it globally.
Deployment Steps
-
Clone the repository using git:
git clone https://github.com/CutTheCrapTech/email-gateway-cloudflare.git -
Install Wrangler (and project dependencies):
cd packages/cloudflare-worker
pnpm install -
Authenticate with Cloudflare:
npx wrangler loginFollow the prompts in your browser to authenticate your Wrangler CLI with your Cloudflare account.
-
Build the worker:
pnpm run buildThis command compiles your worker code into a deployable JavaScript file.
-
Create configuration file:
cp wrangler.toml.template wrangler.tomlEdit the
wrangler.tomlfile with your specific values forname,main,compatibility_date,EMAIL_OPTIONS, and[[email]]section as described in the Configuration section. -
Set secrets:
wrangler secret put EMAIL_SECRET_MAPPINGWhen prompted, paste your JSON string for
EMAIL_SECRET_MAPPING(e.g.,{"secret1": "user1@gmail.com", "secret2": "user2@gmail.com"}). -
Deploy:
wrangler deployThis command deploys your worker to Cloudflare.