Bước 1: Chuẩn bị resource remote Step 1: Prepare Remote Resources ជំហាន 1: រៀបចំ resource remote
- Chúng ta đang xây What we're building អ្វីដែលយើងកំពុងសង់
- Your D1 database schema applied to the remote (production) database.
- Vì sao quan trọng Why this matters ហេតុអ្វីសំខាន់
- In Step 4 you ran the schema migration with --local, which only writes to a local SQLite file. The remote database needs the base schema before deploying.
First, verify you are authenticated:
First, verify you are authenticated:
First, verify you are authenticated:
npx wrangler whoami Apply the base schema to the remote D1 database. The summary column migration was already applied remotely in Step 5, so you only need the initial schema:
Apply the base schema to the remote D1 database. The summary column migration was already applied remotely in Step 5, so you only need the initial schema:
Apply the base schema to the remote D1 database. The summary column migration was already applied remotely in Step 5, so you only need the initial schema:
npx wrangler d1 execute bookmark-db --remote --file=./schema.sql You can optionally test against your real remote bindings before deploying:
You can optionally test against your real remote bindings before deploying:
You can optionally test against your real remote bindings before deploying:
npx wrangler dev --remote Bước 2: Deploy Worker Step 2: Deploy Your Worker ជំហាន 2: Deploy Worker
- Chúng ta đang xây What we're building អ្វីដែលយើងកំពុងសង់
- Your Bookmark API deployed to Cloudflare's global network.
- Vì sao quan trọng Why this matters ហេតុអ្វីសំខាន់
- Everything you have built so far only runs locally. One command puts it live across 300+ data centers.
npx wrangler deploy Wrangler outputs your bindings and the live URL:
Wrangler outputs your bindings and the live URL:
Wrangler outputs your bindings and the live URL:
Your Worker has access to the following bindings:
- KV Namespace (env.BOOKMARKS)
- D1 Database (env.DB)
- AI (env.AI)
Deployed bookmark-api triggers
https://bookmark-api.<your-subdomain>.workers.dev Verify it is working:
Verify it is working:
Verify it is working:
# Check the root endpoint
curl -s https://bookmark-api.<your-subdomain>.workers.dev/ | jq Create a bookmark on the live API:
Create a bookmark on the live API:
Create a bookmark on the live API:
curl -X POST https://bookmark-api.<your-subdomain>.workers.dev/bookmarks \
-H "Content-Type: application/json" \
-d '{"url":"https://developers.cloudflare.com/workers/","title":"Workers Docs","tags":"docs"}' Bước 3: Monitor và rollback Step 3: Monitor and Roll Back ជំហាន 3: Monitor និង rollback
- Chúng ta đang xây What we're building អ្វីដែលយើងកំពុងសង់
- Real-time logs from your live Worker and the ability to roll back a bad deploy.
- Vì sao quan trọng Why this matters ហេតុអ្វីសំខាន់
- Production issues happen. Knowing how to observe and revert quickly is essential.
Xem log trực tiếp Stream live logs មើល log ផ្ទាល់
npx wrangler tail This streams console.log output and request metadata from your production Worker in real time.
This streams console.log output and request metadata from your production Worker in real time.
This streams console.log output and request metadata from your production Worker in real time.
Rollback một bản deploy Roll back a deployment Rollback ការដាក់ឱ្យប្រើមួយ
# List recent deployments
npx wrangler deployments list
# Roll back to the previous version
npx wrangler rollback Bạn đã xong lab Workers! You completed the Workers lab! អ្នកបានបញ្ចប់ lab Workers!
You went from a Hello World Worker to a production-deployed API with storage, databases, and AI on Cloudflare's global network.
You went from a Hello World Worker to a production-deployed API with storage, databases, and AI on Cloudflare's global network.
You went from a Hello World Worker to a production-deployed API with storage, databases, and AI on Cloudflare's global network.
What you built
What you built
What you built
- 01 Set up a Cloudflare Worker and deployed Hello World
- 02 Built HTTP routing and request handling with Hono
- 03 Added KV storage for fast edge caching
- 04 Integrated D1 for relational database storage
- 05 Added AI-powered features with Workers AI
- 06 Connected AI Gateway for observability and caching
- 07 Deployed to Cloudflare's global network with secrets and monitoring
What to build next
What to build next
What to build next
Share what you built with #CloudflareWorkers and connect with the community!
Share what you built with #CloudflareWorkers and connect with the community!
Share what you built with #CloudflareWorkers and connect with the community!