Lộ trình đang học Current learning path

Developer Platform Developer Platform

Build và deploy apps trên Cloudflare. Build and deploy apps on Cloudflare.

Về trang lộ trình Track home

Phần 4: Vận hành và bước tiếp Part 4: Operate and level up · Bài 2/2 Lesson 2/2

Turnstile cho form public Turnstile for public forms

Chống bot trên đăng ký workshop, contact form. Verify token server-side trước khi ghi D1. Stop bots on workshop signup and contact forms. Verify tokens server-side before writing to D1.

Các bước thực hiện Step-by-step

  1. Turnstile dashboard → Create widget → copy site key + secret. Turnstile dashboard → Create widget → copy site key + secret.
  2. Embed widget trên form; gửi token tới API. Embed widget on form; send token to API.
  3. Server verify: POST `https://challenges.cloudflare.com/turnstile/v0/siteverify`. Server verify: POST `https://challenges.cloudflare.com/turnstile/v0/siteverify`.
  4. Chỉ ghi DB sau khi verify success. Only write to DB after successful verify.

Giải thích chi tiết Detailed explanation

Turnstile thay CAPTCHA khó chịu — bảo vệ form public mà UX tốt hơn. Turnstile replaces painful CAPTCHAs — protects public forms with better UX.

Lưu ý (best practices) Note (best practices)

Secret Turnstile và credential khác lưu bằng `wrangler secret put`, không đặt trong source hay client build. Chỉ biến `PUBLIC_*` được embed phía client. Store Turnstile secrets and other credentials with `wrangler secret put`, not in source or client builds. Only `PUBLIC_*` variables belong in the client.

Nguồn: Source: Workers Best Practices Workers Best Practices

Ví dụ triển khai (Cloudflare Resources) Deployment examples (Cloudflare Resources)

Ví dụ chính thức từ Cloudflare Resources — gợi ý theo chủ đề bài học trong lộ trình này. Official examples from Cloudflare Resources — matched to this lesson within this path.

Xem thêm ví dụ trong lộ trình → More examples in this path →

Tài liệu Cloudflare Developers Cloudflare Developer docs

Sản phẩm liên quan Related products

Học xong hoặc muốn đổi hướng? Finished or want a different path?

Ba lộ trình độc lập — mỗi lộ trình chỉ gồm bài học và tài liệu trong phạm vi đó. Chọn lộ trình khác khi sẵn sàng, không cần học song song. Three independent paths — each includes only lessons and materials for that scope. Switch when you are ready; no need to study paths in parallel.

Chưa chắc — làm bài chọn lộ trình Not sure — use the path selector · So sánh cả ba lộ trình Compare all three paths