https://github.com/powerfulyang/cloudflare-worker-tutorial
The backend API is developed using a D1 database and Zod with OpenAPI integration, and it is hosted on Cloudflare Workers utilizing Hono.
https://github.com/powerfulyang/cloudflare-worker-tutorial
cloudflare-workers d1 d1-database hono
Last synced: 3 months ago
JSON representation
The backend API is developed using a D1 database and Zod with OpenAPI integration, and it is hosted on Cloudflare Workers utilizing Hono.
- Host: GitHub
- URL: https://github.com/powerfulyang/cloudflare-worker-tutorial
- Owner: powerfulyang
- License: mit
- Created: 2023-09-19T06:23:21.000Z (about 2 years ago)
- Default Branch: master
- Last Pushed: 2025-04-12T08:12:56.000Z (6 months ago)
- Last Synced: 2025-04-20T23:13:09.078Z (6 months ago)
- Topics: cloudflare-workers, d1, d1-database, hono
- Language: TypeScript
- Homepage: https://life.littleeleven.com
- Size: 2.63 MB
- Stars: 13
- Watchers: 2
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# A Comprehensive Cloudflare Workers Tutorial
[](https://deploy.workers.cloudflare.com/?url=https://github.com/powerfulyang/cloudflare-worker-tutorial)
## Introduction
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
## Install Dependencies
Recommended to use [pnpm](https://pnpm.io/installation) to install dependencies
```bash
pnpm install
```## Configure wrangler
### Configure D1 database
> Related documentation: https://developers.cloudflare.com/workers/wrangler/commands/#d1
Set the `d1_database` field in `wrangler.toml` to your database information (**required**)
Example:
```toml
[[d1_databases]]
binding = "DB"
database_name = ""
database_id = ""
```### Sync table structure
Sync the sql files of `drizzle`, execute the following command using `d1 execute` command
```bash
wrangler d1 execute eleven --file .\drizzle\0000_reflective_dracula.sql
```### Configure R2 bucket
Set the `r2_bucket` field in `wrangler.toml` to your bucket information (**required**)
Example:
```toml
[[r2_buckets]]
binding = "BUCKET"
bucket_name = ""
```## Start local development server
Execute the following command to start the local development server
```bash
# run your Worker in an ideal development workflow (with a local server, file watcher & more)
pnpm run start:local
```## Test
### Unit test
```bash
pnpm run unit:test
```### Integration test
```bash
pnpm run e2e:test
```## Deploy
```bash
# deploy your Worker globally to the Cloudflare network (update your wrangler.toml file for configuration)
pnpm run deploy
```