Cloudflare Workers + D1
Deploy Calends to your Cloudflare account with D1, scheduled jobs and optional email reminders.
Calends is a Cloudflare Worker: the front end is served as the Worker’s static assets, data lives in D1 (SQLite), and reminders and exchange rates run on a cron trigger. Usage and cost depend on your Cloudflare account’s current plan and quotas.
Requirements
Section titled “Requirements”- A Cloudflare account;
- for command-line deploys, Node.js 22 and git.
One-click deploy
Section titled “One-click deploy”Open Deploy to Cloudflare and follow the steps to copy the repository into your GitHub account and deploy it.
Then, in the Cloudflare dashboard, open the Worker’s Settings → Variables and Secrets and add a secret named SETUP_TOKEN with a long random value. Without it you can’t set a password.
Command-line deploy
Section titled “Command-line deploy”-
Clone and install:
终端窗口 git clone https://github.com/imetn/calends && cd calendsnpm ci -
Sign in to Cloudflare and check that
npx wrangler whoamishows your account:终端窗口 npx wrangler login -
Set the setup token:
终端窗口 npx wrangler secret put SETUP_TOKENopenssl rand -base64 24is one way to generate a random value. -
Deploy:
终端窗口 npm run deploy -
Open
https://calends.<your-subdomain>.workers.dev/admin, enter the setup token and choose your password.
npm run deploy does the following:
- generates the migration and translation files, type-checks, and builds the front end with Vite;
- deploys the Worker with
wrangler deploy. On the first deploy, a D1 database namedcalendsis created automatically — nodatabase_idto fill in; - applies all migrations to the remote database.
The Worker also checks for and applies missing migrations the first time each instance handles a request, so one-click deployments work too.
wrangler.jsonc
Section titled “wrangler.jsonc”The wrangler.jsonc in the repository is ready to go:
| Setting | What it does |
|---|---|
assets |
Front-end assets. /api/*, /cal/* and /mcp go to the Worker first; other paths fall back to the single-page app. |
d1_databases |
Binding DB, database calends. |
triggers.crons |
5 * * * *: runs at minute 5 of every hour. Reminders are only sent at your configured hour; exchange rates are refreshed if they’re more than 20 hours old. |
observability |
Workers logs on, so reminder results and migrations show up in the dashboard. |
Email reminders
Section titled “Email reminders”Email reminders use Cloudflare Email Sending. Skip this section if you don’t need email; no other channel needs server-side configuration.
-
Enable email sending for your domain in Cloudflare and verify a sender address, such as
[email protected]. -
In
wrangler.jsonc, uncomment and edit these two entries:"vars": { "SITE_URL": "https://calends.example.com", "MAIL_FROM": "[email protected]", "MAIL_FROM_NAME": "Calends" }, -
Deploy again:
npm run deploy. -
Under Settings → Notification channels, add an email channel with your address and click Test.
Custom domain
Section titled “Custom domain”Usage includes Workers requests, D1 reads, writes and storage, Cron, and optional email sending. Check actual usage and current quotas in your Cloudflare dashboard. The built-in assistant’s DeepSeek usage is billed to your own DeepSeek account, separately from Cloudflare.