You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: products/workers/src/content/learning/getting-started.md
+60-53Lines changed: 60 additions & 53 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -47,7 +47,9 @@ $ wrangler --version
47
47
48
48
## 3. Configure the Workers CLI
49
49
50
-
Now that Wrangler is installed, you'll need to give it an API Token for your Cloudflare account. Run the command `wrangler login` and Wrangler will ask to automatically open your web browser to log into your Cloudflare account. If you are in an environment that doesn't have a GUI, you can copy and paste the url into a browser and log in.
50
+
Now that Wrangler is installed, you'll need to give it an API Token for your Cloudflare account.
51
+
52
+
Run the command `wrangler login` and Wrangler will ask to automatically open your web browser to log into your Cloudflare account. If you are in an environment that doesn't have a GUI, you can copy and paste the url into a browser and log in.
51
53
52
54
```bash
53
55
$ wrangler login
@@ -195,55 +197,68 @@ For inspiration, visit [Built with Workers](https://workers.cloudflare.com/built
195
197
196
198
## 6. Preview your project
197
199
198
-
When you’re ready to preview your code, run Wrangler’s `preview` command:
200
+
In order to preview our Worker, we're going to need to configure our project by adding our `Account ID` to our project's `wrangler.toml`.
199
201
200
-
```sh
201
-
~/my-worker $ wrangler preview --watch
202
+
Run the command `wrangler whoami` and copy your `Account ID`.
203
+
204
+
```bash
205
+
$ wrangler whoami
206
+
👋 You are logged in with an API Token, associated with the email '<Your Email>'!
This command will build your project, upload it to a unique URL, and open a tab in your browser to view it. This allows you to quickly test your project running on the actual Workers runtime, and optionally, even share it with others too.
215
+
Then, open up your project's `wrangler.toml` and paste it in as the value for the `account_id` field.
216
+
217
+
```toml
218
+
---
219
+
filename: wrangler.toml
220
+
highlight: [2]
221
+
---
222
+
name = "my-worker"
223
+
account_id = "$yourAccountId"
224
+
```
205
225
206
-
The `--watch` flag tells Wrangler to watch your Workers project directory for changes, and will **automatically update** the preview tab live with the latest URL.
226
+
Once you've done that, you’re ready to preview your code. Run the `wrangler dev` command:
227
+
228
+
```sh
229
+
~/my-worker $ wrangler dev
230
+
💁 watching "./"
231
+
👂 Listening on http://127.0.0.1:8787
232
+
```
233
+
234
+
This command will build your project, run it locally, and return a url for you to visit to preview the worker.
207
235
208
236
<Asideheader="A note about building">
209
237
210
-
Running `wrangler preview` and `wrangler publish` both run `wrangler build` beforehand automatically, but it can be useful to run `build` separately to check for errors. Running `wrangler build` installs the necessary dependencies for your project and compiles it to make it ready for previewing or deployment. Learn [more about Wrangler](/cli-wrangler/commands).
238
+
Running `wrangler dev` and `wrangler publish` both run `wrangler build` beforehand automatically, but it can be useful to run `build` separately to check for errors. Running `wrangler build` installs the necessary dependencies for your project and compiles it to make it ready for previewing or deployment. Learn [more about Wrangler](/cli-wrangler/commands).
211
239
212
240
</Aside>
213
241
214
242
--------------------------------
215
243
216
244
## 7. Configure your project for deployment
217
245
218
-
In order to publish your Workers project on Cloudflare’s global cloud network, you’ll need to configure your project's `wrangler.toml` with an **Account ID**.
219
-
220
-
If deploying on a free workers.dev subdomain, that’s it. If you’re deploying onto your own domain, you’ll additionally need to configure the project with a **Zone ID**.
221
-
222
-
### 7a. Obtaining your Account ID (and Zone ID)
223
-
224
-
#### workers.dev
225
-
226
-
For workers.dev domains, you will just need the Account ID. The easiest way to get it is by running `wrangler whoami`.
227
-
228
-
However, you can also find your Account ID in the Cloudflare dashboard with the following steps:
229
-
230
-
1.[**Log in** to your Cloudflare account](https://dash.cloudflare.com/login) and select **Workers**.
231
-
2. On the right, look for **Account ID** and click **Click to copy** below the input.
232
-
233
-
#### Registered domains
234
-
235
-
For domains that you have registered on Cloudflare, you need both IDs:
236
-
237
-
1.[**Log in** to your Cloudflare account](https://dash.cloudflare.com/login) and select the desired domain.
238
-
2. Select the **Overview** tab on the navigation bar.
239
-
3. Scroll down until you see both **Zone ID** and **Account ID* on the right.
240
-
4. Click **Click to copy** below the input to each.
246
+
To configure your project, we need to fill in a few missing fields in the `wrangler.toml` file in the root of the generated project. This file contains the information Wrangler needs to connect to the Cloudflare Workers API and publish your code.
241
247
242
-
### 7b. Configuring your project
248
+
You should have already filled in the `account_id` field in the last step. If you didn't, you can get your `Account ID` by running `wrangler whoami`.
243
249
244
-
To configure your project, we need to fill in a few missing fields in the `wrangler.toml` file in the root of the generated project. This file contains the information Wrangler needs to connect to the Cloudflare Workers API and publish your code.
250
+
```bash
251
+
$ wrangler whoami
252
+
👋 You are logged in with an API Token, associated with the email '<Your Email>'!
Finally, we need to tell Wrangler where we want to deploy our project.
270
-
271
-
#### Configure for deploying to workers.dev
272
-
273
-
With the `workers_dev` key in `wrangler.toml` set to `true`, Wrangler will publish your project to your `workers.dev` subdomain.
274
-
275
-
```toml
276
-
---
277
-
filename: wrangler.toml
278
-
highlight: [4]
279
-
---
280
-
name = "my-worker"
281
-
account_id = "$yourAccountId"
282
-
type = "webpack"
283
-
workers_dev = true
284
-
```
285
-
286
-
When deploying to a workers.dev subdomain, the **name** field will be used as the secondary subdomain for the deployed script, e.g. `my-worker.my-subdomain.workers.dev`.
284
+
By default, this project will deploy to your workers.dev subdomain. When deploying to a workers.dev subdomain, the **name** field will be used as the secondary subdomain for the deployed script, e.g. `my-worker.my-subdomain.workers.dev`.
287
285
288
286
#### (Optional) Configure for deploying to a registered domain
289
287
290
288
To publish your application on a domain you own, and not a workers.dev subdomain, you can add a `route` key to your `wrangler.toml`.
291
289
290
+
You can get your `zone_id` with the following steps:
291
+
292
+
1.[**Log in** to your Cloudflare account](https://dash.cloudflare.com/login) and select the desired domain.
293
+
2. Select the **Overview** tab on the navigation bar.
294
+
3. Scroll down until you see both **Zone ID** on the right.
295
+
4. Click **Click to copy** below the input.
296
+
292
297
Wrangler’s [environments feature](/platform/environments) allows us to specify multiple different deploy targets for our application. Let's add a `production` environment, passing in a `zone_id` and `route`:
293
298
294
299
```toml
@@ -317,7 +322,7 @@ If your route is configured to a hostname, you will need to add a DNS record to
317
322
318
323
## 8. Publish your project
319
324
320
-
With our project configured, it’s time to publish it. The way we’ve configured it we have two deploy targets we can publish to.
325
+
With our project configured, it’s time to publish it.
321
326
322
327
To deploy to our workers.dev subdomain, we can run:
323
328
@@ -334,7 +339,9 @@ __Note:__ When pushing to workers.dev project for the first time, you may initia
334
339
335
340
</Aside>
336
341
337
-
To deploy to our “production” environment we set in our `wrangler.toml`, we can pass the `--env` flag to the command:
342
+
#### (Optional) Publish your project to a registered domain
343
+
344
+
To deploy to our production environment we set in our `wrangler.toml` in the optional configuration step, we can pass the `--env` flag to the command:
0 commit comments