Skip to content

Commit 9ecfe93

Browse files
committed
[Workers] Add enable/disable, custom domains, and secure access sections to Previews
1 parent 0972b8a commit 9ecfe93

1 file changed

Lines changed: 73 additions & 0 deletions

File tree

src/content/docs/workers/previews/index.mdx

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,79 @@ Workers Builds posts both URLs as a comment on your pull request. `wrangler prev
146146

147147
---
148148

149+
## Enable or disable Preview URLs
150+
151+
You control whether Preview URLs are active through the `previews_enabled` setting on your Worker's subdomain configuration. By default, `previews_enabled` follows the state of your `workers.dev` subdomain -- if you disable your `workers.dev` route, Preview URLs are also disabled unless you explicitly enable them.
152+
153+
You can toggle this through the dashboard, the API, or your Wrangler configuration file:
154+
155+
<WranglerConfig>
156+
157+
```toml
158+
# Explicitly enable Preview URLs
159+
preview_urls = true
160+
```
161+
162+
</WranglerConfig>
163+
164+
For step-by-step instructions, refer to [Toggle Preview URLs](/workers/configuration/routing/workers-dev/).
165+
166+
---
167+
168+
## Use a custom domain for Previews
169+
170+
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.
171+
172+
| URL type | Example |
173+
| ---------- | ----------------------------------- |
174+
| Production | `app.example.com` |
175+
| Preview | `my-feature.app.example.com` |
176+
| Deployment | `f498jo-my-feature.app.example.com` |
177+
178+
To enable Previews on a custom domain via the API, set `previews_enabled` to `true`:
179+
180+
```bash
181+
curl -X PUT \
182+
"https://api.cloudflare.com/client/v4/accounts/$ACCOUNT_ID/workers/domains" \
183+
-H "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
184+
-H "Content-Type: application/json" \
185+
-d '{
186+
"zone_id": "<ZONE_ID>",
187+
"hostname": "app.example.com",
188+
"service": "my-worker",
189+
"previews_enabled": true
190+
}'
191+
```
192+
193+
Or in your Wrangler configuration file:
194+
195+
<WranglerConfig>
196+
197+
```toml
198+
[[routes]]
199+
pattern = "app.example.com"
200+
custom_domain = true
201+
previews_enabled = true
202+
```
203+
204+
</WranglerConfig>
205+
206+
You can also disable production routing on a custom domain while keeping Previews active by setting `production_enabled` to `false` -- this serves only Preview traffic on that domain.
207+
208+
---
209+
210+
## Secure access to Previews
211+
212+
To restrict who can access your Preview URLs, you can enable [Cloudflare Access](/cloudflare-one/access-controls/policies/) with a single click in your Worker's settings. This protects both Preview URLs and Deployment URLs.
213+
214+
1. Go to **Workers & Pages** > your Worker > **Settings** > **Domains & Routes**.
215+
2. For Preview URLs, select **Enable Cloudflare Access**.
216+
3. Optionally, select **Manage Cloudflare Access** to configure which users, groups, or email addresses are authorized.
217+
218+
For more information on configuring access policies, refer to [Access policies](/cloudflare-one/access-controls/policies/).
219+
220+
---
221+
149222
## Observability and logging
150223

151224
Each Preview runs its own observability and logging settings, independent of your production Worker. This means you can:

0 commit comments

Comments
 (0)