0Pricing
Edge Computing with Cloudflare Workers & Deno · บทเรียน

การเผยแพร่ Worker แรกของคุณ

เรียนรู้ขั้นตอนการเผยแพร่ Worker ไปยังเครือข่ายเอดจ์ของ Cloudflare และทดสอบการทำงานจริง

การเผยแพร่ Worker แรกของคุณ เป็นบทเรียน Edge Computing with Cloudflare Workers & Deno ฟรีบน CoddyKit นี่คือบทเรียนที่ 3 จากทั้งหมด 4 บทเรียน คุณสามารถอ่านบทเรียนทั้งหมดด้านล่างฟรี — จากนั้นลองปฏิบัติด้วยตัวคุณเองในเบราว์เซอร์พร้อมตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7 บทเรียนนี้เป็นส่วนหนึ่งของเส้นทางการเรียน Edge Computing with Cloudflare Workers & Deno และความก้าวหน้าของคุณจะซิงค์ข้ามเว็บและแอป CoddyKit คอร์ส Edge Computing with Cloudflare Workers & Deno มีบทเรียนทั้งหมด 4 บทเรียน

บางส่วนของบทเรียนนี้ยังไม่ได้รับการแปล และแสดงเป็นภาษาอังกฤษ

Ready to Go Live!

You've learned to set up your environment and write a basic Cloudflare Worker. Now, let's make it accessible to the world!

Deploying your Worker means pushing your code to Cloudflare's global network, making it run at the 'edge' – closer to your users.

Before You Publish

Before deploying, ensure you've completed a couple of essential steps:

  • Cloudflare Account: You need an active Cloudflare account.
  • Wrangler Login: You must be logged in to Wrangler CLI. If not, run wrangler login to authenticate with your Cloudflare account.

These prerequisites ensure Wrangler has permission to deploy to your account.

The `wrangler publish` Command

The core command for deploying your Cloudflare Worker is wrangler publish.

You run this command from within your Worker project directory. It handles everything from bundling your code to updating it on Cloudflare's edge network.

What `publish` Does

When you run wrangler publish, several things happen:

  • Bundling: Your Worker code (often JavaScript or TypeScript) is processed and optimized.
  • Uploading: The bundled code is securely uploaded to Cloudflare's global network.
  • Deployment: Cloudflare then makes your Worker live, routing requests to it from the edge closest to the user.

This process is usually very fast!

Our Example Worker

Let's use a simple 'Hello from the Edge!' Worker for deployment. This Worker responds to any incoming request with a plain text message.

Try running this example locally first, then we'll deploy it.

export default {
  async fetch(request) {
    return new Response("Hello from the Edge!", {
      headers: { 'content-type': 'text/plain' },
    });
  },
};

Deploying Your Worker

Assuming you have the example Worker code in a project folder (e.g., my-first-worker) and have run wrangler login, navigate to that directory in your terminal.

Then, simply execute the publish command:

cd my-first-worker
wrangler publish

Deployment Confirmation

After running wrangler publish, you'll see output in your terminal indicating success. It will also provide the public URL where your Worker is now live.

This URL typically looks like https://your-worker-name.your-username.workers.dev.

Testing Your Live Worker

Now that your Worker is deployed, let's test it! You can use your web browser or a command-line tool like curl.

Open your browser and navigate to the URL provided by wrangler publish. You should see 'Hello from the Edge!'.

curl https://your-worker-name.your-username.workers.dev

Updating Your Worker

The beauty of Workers is how easy it is to update them. If you make changes to your Worker's code, simply save your changes and run wrangler publish again.

Cloudflare will automatically update your live Worker with the new code, often within seconds!

Deployment Process Check

You've just deployed your first Worker! Let's quickly review the steps involved.

Recap: Your Worker is Live!

Congratulations! You've successfully deployed your first Cloudflare Worker to the edge network.

  • You used wrangler publish to deploy your code.
  • You verified its live functionality via its public URL.
  • You learned that updates are as simple as running publish again.

Your code is now running globally, closer to users than ever before!

คำถามที่พบบ่อย

บทเรียน “การเผยแพร่ Worker แรกของคุณ” ฟรีหรือไม่

ใช่ — ข้อความเต็มของ “การเผยแพร่ Worker แรกของคุณ” ฟรีให้อ่านที่นี่บนเว็บ เพื่อปฏิบัติแบบโต้ตอบ (ตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7) และปลดล็อคส่วนที่เหลือของคอร์ส Edge Computing with Cloudflare Workers & Deno ให้อัปเกรดเป็น CoddyKit PRO คอร์ส Edge Computing with Cloudflare Workers & Deno มีบทเรียนทั้งหมด 4 บทเรียน

คุณจะเรียนรู้อะไรในบทเรียน “การเผยแพร่ Worker แรกของคุณ”

เรียนรู้ขั้นตอนการเผยแพร่ Worker ไปยังเครือข่ายเอดจ์ของ Cloudflare และทดสอบการทำงานจริง คุณปฏิบัติ Edge Computing with Cloudflare Workers & Deno ด้วยโค้ดที่ใช้งานได้จริงที่คุณเรียกใช้โดยตรงในเบราว์เซอร์ และติวเตอร์ AI ตลอด 24/7 ตอบคำถามของคุณขณะที่คุณไปผ่านบทเรียน

คุณต้องมีประสบการณ์ก่อนที่จะเริ่มเรียน Edge Computing with Cloudflare Workers & Deno หรือไม่

ไม่จำเป็นต้องมีประสบการณ์มาก่อน Edge Computing with Cloudflare Workers & Deno บน CoddyKit ออกแบบมาสำหรับผู้เริ่มต้นไปจนถึงผู้เรียนขั้นสูง คุณสามารถเริ่มต้นที่นี่หรือเริ่มจากตัวแรกและเรียนด้วยความเร็วของคุณเอง นี่คือบทเรียนที่ 3 จากทั้งหมด 4 บทเรียน

บทเรียน “การเผยแพร่ Worker แรกของคุณ” ใช้เวลานานแค่ไหน

บทเรียน CoddyKit ส่วนใหญ่ใช้เวลาประมาณ 5–10 นาที แต่ละบทเรียนจึงสั้นและเป็นแบบโต้ตอบ คุณสามารถก้าวหน้าอย่างต่อเนื่องและกลับมาเรียนต่อจากตรงที่เพิ่งหยุดบนเว็บและแอปได้เลย

ฉันเขียนและรันโค้ดในบทเรียน Edge Computing with Cloudflare Workers & Deno นี้ได้ไหม

ได้ บทเรียน Edge Computing with Cloudflare Workers & Deno ทุกบทมีตัวแก้ไขโค้ดในตัว คุณจึงเขียนและรันโค้ดจริงได้เลยในเบราว์เซอร์ และได้รับข้อเสนอแนะจาก AI ในทันที — ไม่ต้องติดตั้งในเครื่องของคุณ

บทเรียนทั้งหมดในหลักสูตรนี้

  1. การตั้งค่าสภาพแวดล้อม Worker
  2. การจัดการคำขอ HTTP
  3. การเผยแพร่ Worker แรกของคุณ
  4. ตัวแปรสภาพแวดล้อมและข้อมูลลับใน Workers
← กลับไปที่ Edge Computing with Cloudflare Workers & Deno