Zum Inhalt springen

Quickstart: deploy to Cloudflare Workers

Dieser Inhalt ist noch nicht in deiner Sprache verfügbar.

Check first: can I approve the app myself?

Section titled “Check first: can I approve the app myself?”

If you connect a work or school Microsoft account, check this before you deploy. The tenant decides whether users may approve apps. If it does not allow that, the first sign-in stops with a consent error, and an administrator of the tenant has to approve the app.

Microsoft Entra app shows where to find this setting. The error page contains a request that you can copy for the administrator. See Troubleshooting.

You need:

  • A Cloudflare account. The free plan is enough.
  • An account at one provider to start: Microsoft 365 or Google.
  • Rights to create an OAuth app at that provider: an app registration in Microsoft Entra, or a project in Google Cloud.
  • A tool to generate two random secrets (step 1).
  • For the manual deploy only: Node 22 and pnpm 10.

The OAuth app of the provider takes the most effort. This page gives no time estimate, because none has been measured.

To mirror, you need two calendars. They can be two accounts at the same provider, for example a work and a private Microsoft account. Add the second provider later, if you need it.

The order matters. The deploy form needs the two secrets, so you generate them first. The OAuth app needs the address of your Worker, and you get the address only after the deploy. So you deploy second, create the OAuth app after that, and set its secrets last.

The form of the deploy button asks for both values at once, so create them first. Use any one of these. Keep the values: you cannot read a secret again after you save it.

Tool SESSION_SECRET TOKEN_ENCRYPTION_KEY
openssl (macOS, Linux) openssl rand -base64 48 openssl rand -base64 32
PowerShell (Windows) $b = New-Object byte[] 48; [Security.Cryptography.RandomNumberGenerator]::Create().GetBytes($b); [Convert]::ToBase64String($b) $b = New-Object byte[] 32; [Security.Cryptography.RandomNumberGenerator]::Create().GetBytes($b); [Convert]::ToBase64String($b)
Node.js node -e "console.log(require('crypto').randomBytes(48).toString('base64'))" node -e "console.log(require('crypto').randomBytes(32).toString('base64'))"

SESSION_SECRET needs at least 32 characters. TOKEN_ENCRYPTION_KEY must decode to exactly 32 bytes, so do not change the number 32.

Deploy to Cloudflare

The button creates the Worker, the D1 database and the Durable Object in your account. In its form:

  • Paste in SESSION_SECRET and TOKEN_ENCRYPTION_KEY from step 1.
  • Leave MICROSOFT_CLIENT_ID, MICROSOFT_CLIENT_SECRET, GOOGLE_CLIENT_ID and GOOGLE_CLIENT_SECRET empty. You do not have them yet.

Until you do this, your Worker shows a checklist and no sign-in page. In the Cloudflare dashboard, open Workers & Pages, your Worker, Settings, Variables and Secrets. Add these as Text variables:

Name Value
ALLOWED_EMAILS Your address. For a team, set ALLOWED_DOMAINS to your domain instead.
ADMIN_EMAILS Your address.
TIME_ZONE Your time zone, for example Europe/Vienna. The default is UTC.
DATA_JURISDICTION eu, if the data must stay in the EU. Set it now, see the warning below.

The deploy keeps these values. A later deploy does not reset them, because wrangler.jsonc does not list them and sets keep_vars.

If you cloned the repository, you can set a secret with pnpm wrangler secret put <NAME> instead of the dashboard. The dashboard works without any local tools.

On the page of your Worker in the dashboard, open Settings, then Domains & Routes. The address looks like https://slotmirror.<your-subdomain>.workers.dev. You need it in the next step. If you use a custom domain, use its address instead, here and in the OAuth app. Then always open slotmirror through that domain. The redirect URI comes from the address in your browser, so sign-in fails on the workers.dev address.

Add one more variable: PUBLIC_URL, set to this address, without a trailing slash. With it, Microsoft and Google notify the Worker about changes, and mirrored blocks update when they report a change. Without it, the Worker polls every 10 minutes.

Choose one. The redirect address uses the address from step 4.

In Variables and Secrets, add these as Secret, with the values from the OAuth app:

  • Microsoft: MICROSOFT_CLIENT_ID and MICROSOFT_CLIENT_SECRET
  • Google: GOOGLE_CLIENT_ID and GOOGLE_CLIENT_SECRET

Save and deploy. Reload your Worker. If the checklist still shows, it names what is missing. If you set SIGN_IN_PROVIDERS, write both providers as microsoft,google. The word both is not a valid value, and the checklist shows the value it read.

Open the address of your Worker, sign in, and connect your calendars on the Calendars page with Connect calendar. If a sign-in fails, the error page shows a code. Look it up in Troubleshooting. To add the other provider later, repeat steps 5 and 6 for it.

  1. Open the Mirroring page. While nothing is mirrored, it shows Nothing is mirrored yet. Choose Mirror all as busy. Each calendar then shows the events of the others as busy. See below.
  2. In one calendar, create a test event for tomorrow.
  3. Watch the other calendar. With PUBLIC_URL, the copy appears when the notification arrives. Without it, it appears at the next run, after up to 10 minutes.

When the copy appears, the setup works.

You need Node 22 and pnpm 10.

Terminal window
git clone https://github.com/slotmirror/slotmirror && cd slotmirror
pnpm install
pnpm wrangler login
pnpm wrangler d1 create slotmirror # add --jurisdiction=eu to keep data in the EU
# copy the database_id into wrangler.jsonc, see below
pnpm wrangler secret put SESSION_SECRET # generate it as shown above
pnpm wrangler secret put TOKEN_ENCRYPTION_KEY
pnpm run deploy # applies the migrations, then deploys

wrangler d1 create prints the new database as a configuration block, similar to this one. The ID is an example:

{
"d1_databases": [
{
"binding": "slotmirror",
"database_name": "slotmirror",
"database_id": "11111111-2222-3333-4444-555555555555",
},
],
}

In wrangler.jsonc, replace only the database_id of the existing d1_databases entry with this value. Keep "binding": "DB". The code reads the database under that name, and the printed binding does not match it. If Wrangler offers to add the database to your configuration for you, decline.

Then follow steps 3 to 8. Set the provider secrets with pnpm wrangler secret put after step 5.

All variables and secrets are in the settings reference. To move to a newer version later, see Updating your deployment.

Connected accounts, in the previous interface

  1. Connect each calendar on the Calendars page with Connect calendar.
  2. Open Mirroring and choose Mirror all as busy. Each calendar then shows the events of the others as busy. By default, the setting What others see is Private event: people who can see the calendar see a private event, or “Busy” in Google Calendar, and not the title.
  3. For more detail in one direction, open its row on the Mirroring page. Under What is copied, choose Not copied, Busy only, Title or Everything. The panel shows what you and others will see.
  4. Choose Save. The changes apply within a few minutes to the copies that exist.

On the Calendars page you also choose which calendars of one account are copied. Open the panel of the account, and turn on the calendars under Copy from these calendars.

A source card with several calendars of one account, in the previous interface