Deploy to Cloudflare
Goal: a Worker with a D1 database and an R2 bucket, deployed with Wrangler.
- Declare the bindings in a
wrangler.jsoncin the app root. Hamur merges it into.output/wrangler.jsonand keeps your entries.@hamur/dbuses the D1 bindingDBand@hamur/blobthe R2 bindingBLOBon this preset, and a binding missing from the file fails the build with a message that names it:
{
"name": "my-app",
"d1_databases": [
{ "binding": "DB", "database_name": "my-app", "database_id": "<the id wrangler d1 create printed>" },
],
"r2_buckets": [{ "binding": "BLOB", "bucket_name": "my-app-uploads" }],
}
- Create the database, build, set the app key as a secret, apply the migrations of
server/db/migrations/and deploy. Wrangler owns D1 migrations, sodb.migrateis not used here.hamur deploy --prebuiltrunswrangler deploy --config .output/wrangler.jsonon what was just built:
bunx wrangler d1 create my-app
hamur build --preset cloudflare
bunx wrangler secret put HAMUR_KEY --config .output/wrangler.json
bunx wrangler d1 migrations apply my-app --remote --config .output/wrangler.json
hamur deploy --prebuilt
- Mind two limits. Hashing a password costs CPU on Workers, and a Free plan cannot hash at the default count; see Passwords. The
fsblob driver and the SQLite connectors do not run on Workers, which is why the sample uses D1 and R2.
See also: Cloudflare Workers, hamur deploy, A SQLite database.