This tutorial will guide you step by step from scratch on how to develop your own API service using Cloudflare Workers.
Preview: https://life.littleeleven.com
Recommended to use pnpm to install dependencies
pnpm install
Related documentation: https://developers.cloudflare.com/workers/wrangler/commands/#d1
Set the d1_database
field in wrangler.toml
to your database information (required)
Example:
[[d1_databases]]
binding = "DB"
database_name = "<database-name>"
database_id = "<database-id>"
Sync the sql files of drizzle
, execute the following command using d1 execute
command
wrangler d1 execute eleven --file .\drizzle\0000_reflective_dracula.sql
Set the r2_bucket
field in wrangler.toml
to your bucket information (required)
Example:
[[r2_buckets]]
binding = "BUCKET"
bucket_name = "<bucket-name>"
Execute the following command to start the local development server
# run your Worker in an ideal development workflow (with a local server, file watcher & more)
pnpm run start:local
pnpm run unit:test
pnpm run e2e:test
# deploy your Worker globally to the Cloudflare network (update your wrangler.toml file for configuration)
pnpm run deploy