0Pricing
Edge Computing with Cloudflare Workers & Deno · 课时

部署您的第一个 Worker

学习将您的 Worker 部署到 Cloudflare 边缘网络,并测试其在线运行功能的步骤。

部署您的第一个 Worker 是 CoddyKit 上的免费 Edge Computing with Cloudflare Workers & Deno 课时。 这是第 3 节课,共 4 节。 你可以在下方免费阅读本课时的完整内容 — 然后在浏览器中使用内置代码编辑器和全天候 AI 导师进行实践。 这是 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 导师)并解锁 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 导师会在你学习这节课的过程中回答你的问题。

学习 Edge Computing with Cloudflare Workers & Deno 需要有经验吗?

无需任何先前经验。CoddyKit 上的 Edge Computing with Cloudflare Workers & Deno 课程适合初学者到高级学习者,你可以从这里开始或从头开始,按照自己的节奏学习。 这是第 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