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: src/content/docs/workers/previews/api.mdx
+9-9Lines changed: 9 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -10,7 +10,7 @@ description: Understand the Previews data model and use the API to manage Previe
10
10
11
11
import { Details } from"~/components";
12
12
13
-
This guide walks you through the Workers Previews API from the ground up. It assumes you can make authenticated requests to the Cloudflare API and that you already have a production Worker deployed.
13
+
This guide walks you through the Workers Previews API from the ground up. For a higher-level introduction to what Previews are and how to get started, refer to the [Previews overview](/workers/previews/). This page assumes you can make authenticated requests to the Cloudflare API and that you already have a production Worker deployed.
14
14
15
15
Every endpoint below lives under a common base path:
16
16
@@ -68,7 +68,7 @@ Anywhere the API accepts a `{preview_id}` path parameter, you can pass any of th
68
68
69
69
### What a Preview contains vs. what a Deployment contains
70
70
71
-
The Previews API splits configuration into two layers: the **Preview layer** and the **Deployment layer**.
71
+
The Previews API splits configuration into two layers: the **Preview layer** and the **Deployment layer**. Understanding this split is key to working with the API.
72
72
73
73
The **Preview layer** holds settings that apply across all of a Preview's Deployments: observability, log routing (`logpush`, `tail_consumers`), and organizational metadata (`tags`). These persist for the lifetime of the Preview regardless of how many Deployments you create.
74
74
@@ -195,7 +195,7 @@ The Deployment object represents the Deployment layer. Here is its full shape:
195
195
196
196
## Preview Defaults
197
197
198
-
Your production Worker can store a property called `preview_defaults`. It is a template of starting values that Cloudflare applies whenever you create a new Preview or Deployment. It is not a standalone API resource -- you read and write it through the existing Worker endpoints (`PUT` or `PATCH` on `/workers/workers/{worker_id}`).
198
+
Your production Worker can store a property called **`preview_defaults`**. It is a template of starting values that Cloudflare applies whenever you create a new Preview or Deployment. It is not a standalone API resource -- you read and write it through the existing Worker endpoints (`PUT` or `PATCH` on `/workers/workers/{worker_id}`). You can also configure these from the dashboard or your Wrangler configuration file -- refer to [Set up Previews](/workers/previews/#set-up-previews) for a walkthrough.
199
199
200
200
`preview_defaults` carries values for both layers:
201
201
@@ -317,13 +317,13 @@ Previews and Deployments each receive automatically assigned URLs. The format de
A Preview URL always points to the latest Deployment. A Deployment URL always points to that exact immutable Deployment.
320
+
A **Preview URL** always points to the latest Deployment. A **Deployment URL** always points to that exact immutable Deployment. For a quick summary of both URL types, refer to [Preview URLs and Deployment URLs](/workers/previews/#preview-urls-and-deployment-urls).
321
321
322
-
These URLs appear in the read-only `urls` field on both the Preview and Deployment objects.
322
+
These URLs appear in the read-only `urls` field on both the [Preview object](#preview-object)and [Deployment object](#deployment-object).
323
323
324
324
### Custom domains
325
325
326
-
You can route Previews through your own domain by enabling `previews_enabled` on a Worker custom domain:
326
+
You can route Previews through your own domain by enabling `previews_enabled` on a Worker custom domain. For Wrangler configuration and dashboard instructions, refer to [Use a custom domain for Previews](/workers/previews/#use-a-custom-domain-for-previews).
327
327
328
328
```bash
329
329
curl -X PUT \
@@ -359,7 +359,7 @@ Both `production_enabled` and `previews_enabled` are optional and default to `tr
359
359
360
360
### Set Preview Defaults
361
361
362
-
Use the existing Worker endpoints. Include `preview_defaults` in the body:
362
+
Use the existing Worker endpoints. Include `preview_defaults` in the body. Refer to [Preview Defaults](#preview-defaults) for how these values merge with individual Preview and Deployment requests.
363
363
364
364
```txt
365
365
PUT /workers/workers/{worker_id}
@@ -525,7 +525,7 @@ DELETE /{deployment_id}
525
525
526
526
### 1. Set Preview Defaults on your Worker
527
527
528
-
This is a one-time setup step. You are patching the parent Worker, not creating a new resource.
528
+
This is a one-time setup step. You are patching the parent Worker, not creating a new resource. You can also do this from the dashboard or Wrangler -- refer to [Set up Previews](/workers/previews/#set-up-previews).
529
529
530
530
```bash
531
531
curl -X PATCH \
@@ -557,7 +557,7 @@ curl -X POST \
557
557
}'
558
558
```
559
559
560
-
The response includes the Preview's `id`, `slug` (`feature-auth`), and `urls`. The `observability` setting comes from `preview_defaults` because you did not override it.
560
+
The response includes the Preview's `id`, `slug` (`feature-auth`), and `urls`. The `observability` setting comes from `preview_defaults` because you did not override it. Refer to [How defaults merge](#how-defaults-merge) for details on this behavior.
Copy file name to clipboardExpand all lines: src/content/docs/workers/previews/index.mdx
+13-13Lines changed: 13 additions & 13 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -18,9 +18,9 @@ import {
18
18
InlineBadge,
19
19
} from"~/components";
20
20
21
-
A Preview is an isolated copy of your Worker running on its own URL that you use to test changes before deploying to production. A Worker can have many Previews running at the same time, each isolated from each other. Each Preview runs with its own bindings, environment variables, and secrets, so your preview traffic never touches your production data.
21
+
A **Preview** is an isolated copy of your Worker that runs on its own URL, so you can test changes before deploying to production. A Worker can have many Previews running at the same time, each isolated from each other. Each Preview runs with its own [bindings](/workers/runtime-apis/bindings/), environment variables, and secrets, so your preview traffic never touches your production data.
22
22
23
-
Previews are created automatically when you push to any branch other than your tracked branch (usually `main`), or manually with `wrangler preview`.
23
+
Previews are created automatically when you push to any branch other than your tracked branch (usually `main`), or manually with `wrangler preview`. For a deeper look at how Previews and their Deployments are structured, refer to [Previews API](/workers/previews/api/).
24
24
25
25
## Quick start
26
26
@@ -42,17 +42,17 @@ git checkout -b new-feature
42
42
wrangler preview
43
43
```
44
44
45
-
Wrangler builds your code locally and deploys it as a Preview. It prints a **Preview URL** and a **Deployment URL** to your terminal.
45
+
Wrangler builds your code locally and deploys it as a Preview. It prints a **[Preview URL](#preview-urls-and-deployment-urls)** and a **[Deployment URL](#preview-urls-and-deployment-urls)** to your terminal.
46
46
47
47
---
48
48
49
49
## Set up Previews
50
50
51
-
Previews use their own bindings, environment variables, and secrets -- separate from your production Worker settings. Before creating your first Preview, you need to configure what resources and environment variables Previews should use.
51
+
Previews use their own bindings, environment variables, and secrets -- separate from your production Worker settings. Before creating your first Preview, you need to configure what resources and environment variables Previews should use. These are called **[Preview Defaults](/workers/previews/api/#preview-defaults)** -- a template of starting values that every new Preview inherits automatically.
52
52
53
53
### From the dashboard
54
54
55
-
Go to your Worker > **Settings**, and you will see a banner for setting up your default Preview settings. This walks you through the bindings, environment variables, and observability settings you want every Preview to start with. This is the fastest way to get your whole team set up -- anyone who creates a Preview (manually or by pushing a branch) gets the same configuration without needing to specify it themselves.
55
+
Go to your Worker > **Settings**, and you will see a banner for setting up your default Preview settings. This walks you through the bindings, environment variables, and [observability](#observability-and-logging) settings you want every Preview to start with. This is the fastest way to get your whole team set up -- anyone who creates a Preview (manually or by pushing a branch) gets the same configuration without needing to specify it themselves.
56
56
57
57
### From code
58
58
@@ -86,7 +86,7 @@ When you configure settings in both the dashboard and the Wrangler configuration
86
86
87
87
## Deploy a Preview
88
88
89
-
You can deploy a Preview automatically every time you push to a branch using Workers Builds, or manually from the command line with `wrangler preview`.
89
+
You can deploy a Preview automatically every time you push to a branch using [Workers Builds](/workers/ci-cd/builds/), or manually from the command line with `wrangler preview`.
90
90
91
91
### Automate with Workers Builds
92
92
@@ -98,12 +98,12 @@ Connect a GitHub or GitLab repository, and Cloudflare deploys a Preview for you
98
98
99
99
When you push to `main`, Cloudflare builds and deploys your Worker to production using your top-level Wrangler configuration -- your production bindings, environment variables, and secrets. When you push to any other branch, Cloudflare deploys a Preview using your Preview settings instead.
100
100
101
-
The first push to a branch creates a new Preview. Each subsequent push creates a new deployment within that Preview -- an immutable snapshot of your code at that point. This means you can always go back and inspect or compare any previous deployment, even after pushing new changes.
101
+
The first push to a branch creates a new Preview. Each subsequent push creates a new **[Preview Deployment](/workers/previews/api/#preview-deployment)** within that Preview -- an immutable snapshot of your code at that point. This means you can always go back and inspect or compare any previous deployment, even after pushing new changes.
102
102
103
103
A bot comments on your pull request with:
104
104
105
-
- A link to the **Preview URL** (which always serves the latest deployment)
106
-
- A **Deployment URL** (which points to that exact snapshot)
105
+
- A link to the **[Preview URL](#preview-urls-and-deployment-urls)** (which always serves the latest deployment)
106
+
- A **[Deployment URL](#preview-urls-and-deployment-urls)** (which points to that exact snapshot)
107
107
- A link to the build logs
108
108
109
109
### Deploy manually with Wrangler
@@ -128,7 +128,7 @@ Use this for ad-hoc testing, external CI/CD pipelines, or when you are not using
128
128
129
129
## Preview URLs and Deployment URLs
130
130
131
-
When you deploy a Preview, Cloudflare generates two URLs:
131
+
When you deploy a Preview, Cloudflare generates two URLs. For the full URL patterns across `workers.dev`, `cloudflare.app`, and custom domains, refer to [URL structure](/workers/previews/api/#url-structure).
132
132
133
133
-**Preview URL** -- always serves the latest deployment. When you push new code, the Preview URL points to the new deployment automatically. Share this with teammates when you want them to always see your latest changes.
134
134
@@ -165,7 +165,7 @@ preview_urls = true
165
165
166
166
## Use a custom domain for Previews
167
167
168
-
You can serve Previews from your own custom domain instead of (or in addition to) `workers.dev`. When you enable Previews on a custom domain, Cloudflare creates a wildcard DNS record and adds a wildcard SAN to the domain's certificate to cover all Preview subdomains.
168
+
You can serve Previews from your own **custom domain** instead of (or in addition to) `workers.dev`. When you enable Previews on a custom domain, Cloudflare creates a wildcard DNS record and adds a wildcard SAN to the domain's certificate to cover all Preview subdomains. For more details, refer to [Custom domains](/workers/previews/api/#custom-domains).
@@ -225,13 +225,13 @@ Each Preview runs its own observability and logging settings, independent of you
225
225
- Enable [Logpush](/workers/observability/logpush/) to send a Preview's logs to your own storage for debugging.
226
226
- Attach [Tail Workers](/workers/observability/logs/tail-workers/) to a Preview to pipe its logs into a custom analysis pipeline.
227
227
228
-
Configure these in the dashboard under **Workers & Pages** > your Worker > **Settings** > **Preview Defaults**, and Cloudflare applies them to every Preview created for that Worker.
228
+
Configure these in the dashboard under **Workers & Pages** > your Worker > **Settings** > **Preview Defaults**, and Cloudflare applies them to every Preview created for that Worker. For details on how observability settings are structured, refer to the [Preview object](/workers/previews/api/#preview-object).
229
229
230
230
---
231
231
232
232
## Limits and lifecycle
233
233
234
-
- Previews do not count against the account-level Worker limit (100 free / 500 paid). They have a separate limit: **1,000** for free plans, **10,000** for paid plans.
234
+
- Previews do not count against the account-level Worker limit (100 free / 500 paid). They have a separate limit: **1,000** for Free plans, **10,000** for Paid plans.
235
235
- If you hit the limit, creating a new Preview automatically deletes the least-recently-deployed existing Preview to make room.
236
236
- Previews are automatically deleted after a TTL since their last deployment.
237
237
- Previews cannot be addressed by user-managed triggers (routes, cron triggers, queues). They are reachable only through their auto-generated URLs and custom-domain wildcard URLs.
0 commit comments