Implantando seu Primeiro Worker
Aprenda as etapas para implantar seu Worker na rede de borda da Cloudflare e testar sua funcionalidade em funcionamento.
Implantando seu Primeiro Worker é uma aula grátis de Edge Computing with Cloudflare Workers & Deno no CoddyKit. Esta é a aula 3 de 4. Você pode ler a aula completa abaixo gratuitamente — depois pratica ao vivo no navegador com um editor de código integrado e um tutor de IA 24/7. Faz parte do caminho de aprendizado de Edge Computing with Cloudflare Workers & Deno, e seu progresso é sincronizado entre a web e o app CoddyKit. O curso de Edge Computing with Cloudflare Workers & Deno inclui 4 aulas no total.
Partes desta aula ainda não foram traduzidas e aparecem em inglês.
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 loginto 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 publishDeployment 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.devUpdating 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 publishto deploy your code. - You verified its live functionality via its public URL.
- You learned that updates are as simple as running
publishagain.
Your code is now running globally, closer to users than ever before!
Perguntas Frequentes
A aula “Implantando seu Primeiro Worker” é grátis?
Sim — o texto completo de “Implantando seu Primeiro Worker” é grátis para ler aqui na web. Para praticá-la interativamente (um editor de código integrado e um tutor de IA 24/7) e desbloquear o restante do curso de Edge Computing with Cloudflare Workers & Deno, atualize para CoddyKit PRO. O curso de Edge Computing with Cloudflare Workers & Deno inclui 4 aulas no total.
O que vou aprender em “Implantando seu Primeiro Worker”?
Aprenda as etapas para implantar seu Worker na rede de borda da Cloudflare e testar sua funcionalidade em funcionamento. Você pratica Edge Computing with Cloudflare Workers & Deno com código prático que executa diretamente no navegador, e um tutor de IA 24/7 responde suas dúvidas enquanto trabalha na aula.
Preciso ter experiência prévia para começar Edge Computing with Cloudflare Workers & Deno?
Nenhuma experiência prévia é necessária. Edge Computing with Cloudflare Workers & Deno no CoddyKit é estruturado para alunos iniciantes até avançados, então você pode começar aqui ou desde o início e aprender no seu ritmo. Esta é a aula 3 de 4.
Quanto tempo leva a aula “Implantando seu Primeiro Worker”?
A maioria das aulas CoddyKit leva cerca de 5–10 minutos. Cada uma é compacta e interativa, então você faz progresso constante e retoma exatamente de onde parou entre web e app.
Posso escrever e executar código nesta aula de Edge Computing with Cloudflare Workers & Deno?
Sim. Cada aula de Edge Computing with Cloudflare Workers & Deno inclui um editor de código integrado, então você escreve e executa código real direto no navegador e recebe feedback de IA instantaneamente — nenhuma configuração local necessária.
Todas as aulas deste curso
- Configurando o Ambiente do Worker
- Lidando com Requisições HTTP
- Implantando seu Primeiro Worker
- Variáveis de ambiente e segredos em Workers