Skip to content

Cloudflare Setup

Alokai CMS requires three Cloudflare services: D1 (database), R2 (object storage), and KV (cache). Create them before deploying.

Create resources

  1. Create a D1 database

    Terminal window
    wrangler d1 create alokon-db

    Copy the database_id from the output into wrangler.jsonc:

    "d1_databases": [
    {
    "binding": "DB",
    "database_name": "alokon-db",
    "database_id": "<paste-id-here>"
    }
    ]
  2. Create an R2 bucket

    Terminal window
    wrangler r2 bucket create alokon-assets
    "r2_buckets": [
    {
    "binding": "ASSETS",
    "bucket_name": "alokon-assets"
    }
    ]
  3. Create a KV namespace

    Terminal window
    wrangler kv namespace create CACHE

    Copy the id from the output:

    "kv_namespaces": [
    {
    "binding": "CACHE",
    "id": "<paste-id-here>"
    }
    ]
  4. Run migrations on the remote database

    Terminal window
    wrangler d1 migrations apply alokon-db --remote
  5. Seed the remote database

    Terminal window
    wrangler d1 execute alokon-db --remote --file=src/db/migrations/002_seed.sql
  6. Set secrets

    Terminal window
    wrangler secret put AUTH_JWT_SECRET
    # Enter a long random string when prompted
  7. Deploy

    Terminal window
    yarn deploy

Custom domain

In the Cloudflare dashboard, go to Workers & Pages → your worker → Settings → Triggers → Custom Domains and add your domain.

CORS

If your storefront is on a different domain than the Worker, configure CORS in src/server/index.ts. The default dev config allows all origins.

Environment variables in production

Set all variables via Wrangler secrets (for sensitive values) or wrangler.jsonc vars (for non-sensitive):

Terminal window
wrangler secret put AUTH_JWT_SECRET
wrangler secret put OIDC_ISSUER # if using OIDC

Non-sensitive vars can go in wrangler.jsonc under "vars".