Cloudflare Workers Cloudflare Workers Cloudflare Workers · Lab 7/7 Lab 7/7 Lab 7/7 · 5 phút · 5 min · 5 នាទី

07

Deploy production Deploy to Production Deploy ទៅ production

Deploy Bookmark API lên mạng toàn cầu Cloudflare, kiểm tra, monitor và rollback. Deploy your Bookmark API to Cloudflare's global network, verify the deployment, and learn how to monitor and roll back. Deploy Bookmark API ទៅបណ្តាញសកល Cloudflare ពិនិត្យ monitor និង rollback។

Nội dung bước (lệnh, code) giữ nguyên tiếng Anh từ nguồn chính thức. Step body (commands, code) stays in English from the official source. ខ្លឹមសារជំហាន (ពាក្យបញ្ជា និង code) រក្សាភាសាអង់គ្លេសពីប្រភពផ្លូវការ។ labs.cloudflare.dev ↗

Cần trước Prerequisites តម្រូវការជាមុន

  • Đã xong bước 6 Completed Step 6 បានបញ្ចប់ជំហាន 6
  • Tài khoản Cloudflare Cloudflare account គណនី Cloudflare
  • Đã cài Wrangler CLI Wrangler CLI installed បានដំឡើង Wrangler CLI

Bạn sẽ làm được Learning objectives គោលបំណងសិក្សា

  • Ship Worker lên mạng toàn cầu Cloudflare và kiểm tra live Ship a Worker to Cloudflare's global network and verify it is live Ship Worker ទៅបណ្តាញសកល Cloudflare ហើយពិនិត្យថា live
  • Lưu cấu hình nhạy cảm bằng Wrangler secrets Store sensitive configuration securely using Wrangler secrets រក្សាការកំណត់រសើបដោយ Wrangler secrets
  • Monitor traffic production và rollback bản deploy lỗi Monitor production traffic and roll back a bad deployment Monitor traffic production និង rollback ការដាក់ឱ្យប្រើខុស

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:

bash
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:

bash
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:

bash
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.
bash
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:

txt
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:

bash
# 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:

bash
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 ផ្ទាល់

bash
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 ការដាក់ឱ្យប្រើមួយ

bash
# 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

  1. 01 Set up a Cloudflare Worker and deployed Hello World
  2. 02 Built HTTP routing and request handling with Hono
  3. 03 Added KV storage for fast edge caching
  4. 04 Integrated D1 for relational database storage
  5. 05 Added AI-powered features with Workers AI
  6. 06 Connected AI Gateway for observability and caching
  7. 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!