Skip to content

The backend API is developed using a D1 database and Zod with OpenAPI integration, and it is hosted on Cloudflare Workers utilizing Hono.

License

Notifications You must be signed in to change notification settings

piisy/cloudflare-worker-tutorial

Repository files navigation

A Comprehensive Cloudflare Workers Tutorial

Deploy to Cloudflare Workers

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 to install dependencies

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:

[[d1_databases]]
binding = "DB"
database_name = "<database-name>"
database_id = "<database-id>"

Sync table structure

Sync the sql files of drizzle, execute the following command using d1 execute command

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:

[[r2_buckets]]
binding = "BUCKET"
bucket_name = "<bucket-name>"

Start local development server

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

Test

Unit test

pnpm run unit:test

Integration test

pnpm run e2e:test

Deploy

# deploy your Worker globally to the Cloudflare network (update your wrangler.toml file for configuration)
pnpm run deploy

About

The backend API is developed using a D1 database and Zod with OpenAPI integration, and it is hosted on Cloudflare Workers utilizing Hono.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published