Skip to content

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.

  • A Cloudflare account;
  • for command-line deploys, Node.js 22 and git.

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.

  1. Clone and install:

    终端窗口
    git clone https://github.com/imetn/calends && cd calends
    npm ci
  2. Sign in to Cloudflare and check that npx wrangler whoami shows your account:

    终端窗口
    npx wrangler login
  3. Set the setup token:

    终端窗口
    npx wrangler secret put SETUP_TOKEN

    openssl rand -base64 24 is one way to generate a random value.

  4. Deploy:

    终端窗口
    npm run deploy
  5. Open https://calends.<your-subdomain>.workers.dev/admin, enter the setup token and choose your password.

npm run deploy does the following:

  1. generates the migration and translation files, type-checks, and builds the front end with Vite;
  2. deploys the Worker with wrangler deploy. On the first deploy, a D1 database named calends is created automatically — no database_id to fill in;
  3. 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.

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 use Cloudflare Email Sending. Skip this section if you don’t need email; no other channel needs server-side configuration.

  1. Enable email sending for your domain in Cloudflare and verify a sender address, such as [email protected].

  2. In wrangler.jsonc, uncomment and edit these two entries:

    "send_email": [{ "name": "EMAIL", "allowed_sender_addresses": ["[email protected]"] }],
    "vars": { "SITE_URL": "https://calends.example.com", "MAIL_FROM": "[email protected]", "MAIL_FROM_NAME": "Calends" },
  3. Deploy again: npm run deploy.

  4. Under Settings → Notification channels, add an email channel with your address and click Test.

See Custom domain and HTTPS.

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.