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/pages/configuration/preview-deployments.mdx
-3Lines changed: 0 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,7 +1,6 @@
1
1
---
2
2
pcx_content_type: concept
3
3
title: Preview deployments
4
-
5
4
---
6
5
7
6
Preview deployments allow you to preview new versions of your project without deploying it to production. To view preview deployments:
@@ -47,10 +46,8 @@ Note that this will only protect your preview deployments (for example, `373f31e
47
46
48
47
:::note
49
48
50
-
51
49
If you want to enable Access for your `*.pages.dev` domain and your custom domain along with your preview deployments, review [Known issues](/pages/platform/known-issues/#enable-access-on-your-pagesdev-domain) for instructions.
description: Preview URLs allow you to preview new versions of your project without deploying it to production.
9
+
---
10
+
11
+
import { Render } from"~/components";
12
+
13
+
Preview URLs allow you to preview new versions of your Worker without deploying it to production.
14
+
15
+
Every time you create a new [version](/workers/configuration/versions-and-deployments/#versions) of your Worker a unique preview URL is generated. New [versions](/workers/configuration/versions-and-deployments/#versions) of a Worker are created on [`wrangler deploy`](/workers/wrangler/commands/#deploy), [`wrangler versions upload`](/workers/wrangler/commands/#upload) or when you make edits on the Cloudflare dashboard. By default, preview URLs are enabled and available publicly.
16
+
17
+
Preview URLs can be:
18
+
19
+
- Integrated into CI/CD pipelines, allowing automatic generation of preview environments for every pull request.
20
+
- Used for collaboration between teams to test code changes in a live environment and verify updates.
21
+
- Used to test new API endpoints, validate data formats, and ensure backward compatibility with existing services.
22
+
23
+
When testing zone level performance or security featues for a version, we recommended using [version overrides](/workers/configuration/versions-and-deployments/gradual-deployments/#version-overrides) so that your zone's performance and security settings apply.
24
+
25
+
:::note
26
+
Preview URLs are only available for Worker versions uploaded after 2024-09-25.
27
+
:::
28
+
29
+
## View preview URLs using wrangler
30
+
31
+
The [`wrangler versions upload`](/workers/wrangler/commands/#upload) command uploads a new [version](/workers/configuration/versions-and-deployments/#versions) of your Worker and returns a preview URL for each version uploaded.
32
+
33
+
## View preview URLs on the Workers dashboard
34
+
35
+
1. Log in to the [Cloudflare dashboard](https://dash.cloudflare.com/?to=/:account/workers) and select your project.
36
+
2. Head to the "Deployments" tab find the version you would like to view.
37
+
38
+
## Making Preview URLs inaccessible
39
+
40
+
Preview URLs run on your [`workers.dev` subdomain](/workers/configuration/routing/workers-dev/). To make preview URLs inaccessible, you must disable your Workers `workers.dev` subdomain. Learn how to [disable your Workers `workers.dev` subdomain](/workers/configuration/routing/workers-dev/#disabling-workersdev).
41
+
42
+
## Limitations
43
+
44
+
- Preview URLs are not generated for Workers that implement a [Durable Object](/durable-objects/).
45
+
- Preview URLs are not currently generated for [Workers for Platforms](/cloudflare-for-platforms/workers-for-platforms/)[user Workers](/cloudflare-for-platforms/workers-for-platforms/reference/how-workers-for-platforms-works/#user-workers). This is a temporary limitation, we are working to remove it.
46
+
- You cannot currently secure `workers.dev` URLs behind [Cloudflare Access](/cloudflare-one/policies/access/). This is a temporary limitation, we are working to remove it.
Copy file name to clipboardExpand all lines: src/content/docs/workers/configuration/routing/index.mdx
+5-4Lines changed: 5 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,21 +5,22 @@ head: []
5
5
description: Connect your Worker to an external endpoint (via Routes, Custom
6
6
Domains or a `workers.dev` subdomain) such that it can be accessed by the
7
7
Internet.
8
-
9
8
---
10
9
11
10
To allow a Worker to receive inbound HTTP requests, you must connect it to an external endpoint such that it can be accessed by the Internet.
12
11
13
12
There are three types of routes:
14
13
15
-
*[Custom Domains](/workers/configuration/routing/custom-domains): Routes to a domain or subdomain (such as `example.com` or `shop.example.com`) within a Cloudflare zone where the Worker is the origin.
14
+
-[Custom Domains](/workers/configuration/routing/custom-domains): Routes to a domain or subdomain (such as `example.com` or `shop.example.com`) within a Cloudflare zone where the Worker is the origin.
16
15
17
-
*[Routes](/workers/configuration/routing/routes/): Routes that are set within a Cloudflare zone where your origin server, if you have one, is behind a Worker that the Worker can communicate with.
16
+
-[Routes](/workers/configuration/routing/routes/): Routes that are set within a Cloudflare zone where your origin server, if you have one, is behind a Worker that the Worker can communicate with.
18
17
19
-
*[`workers.dev`](/workers/configuration/routing/workers-dev/): The`workers.dev` subdomain route automatically created for your Worker that you can disable.
18
+
-[`workers.dev`](/workers/configuration/routing/workers-dev/): A`workers.dev` subdomain route is automatically created for each Worker to help you getting started quickly. You may chose to [disable](/workers/configuration/routing/workers-dev/) your `workers.dev` subdomain.
20
19
21
20
## What is best for me?
22
21
22
+
It's recommended to run production Workers on a [Workers route or custom domain](/workers/configuration/routing/), rather than on your `workers.dev` subdomain. Your `workers.dev` subdomain is treated as a [Free website](https://www.cloudflare.com/plans/) and is intended for personal or hobby projects that aren't business-critical.
23
+
23
24
Custom Domains are recommended for use cases where your Worker is your application's origin server. Custom Domains can also be invoked within the same zone via `fetch()`, unlike Routes.
24
25
25
26
Routes are recommended for use cases where your application's origin server is external to Cloudflare. Note that Routes cannot be the target of a same-zone `fetch()` call.
Copy file name to clipboardExpand all lines: src/content/docs/workers/configuration/routing/routes.mdx
+18-42Lines changed: 18 additions & 42 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,7 +1,6 @@
1
1
---
2
2
pcx_content_type: concept
3
3
title: Routes
4
-
5
4
---
6
5
7
6
## Background
@@ -10,11 +9,11 @@ Routes allow users to map a URL pattern to a Worker. When a request comes in to
10
9
11
10
Routes are a set of rules that evaluate against a request's URL. Routes are recommended for you if you have a designated application server you always need to communicate with. Calling `fetch()` on the incoming `Request` object will trigger a subrequest to your application server, as defined in the **DNS** settings of your Cloudflare zone.
12
11
13
-
Routes add Workers functionality to your existing proxied hostnames, in front of your application server. These allow your Workers to act as a proxy and perform any necessary work before reaching out to an application server behind Cloudflare.
12
+
Routes add Workers functionality to your existing proxied hostnames, in front of your application server. These allow your Workers to act as a proxy and perform any necessary work before reaching out to an application server behind Cloudflare.
14
13
15
14

16
15
17
-
Routes can `fetch()` Custom Domains and take precedence if configured on the same hostname. If you would like to run a logging Worker in front of your application, for example, you can create a Custom Domain on your application Worker for `app.example.com`, and create a Route for your logging Worker at `app.example.com/*`. Calling `fetch()` will invoke the application Worker on your Custom Domain. Note that Routes cannot be the target of a same-zone `fetch()` call.
16
+
Routes can `fetch()` Custom Domains and take precedence if configured on the same hostname. If you would like to run a logging Worker in front of your application, for example, you can create a Custom Domain on your application Worker for `app.example.com`, and create a Route for your logging Worker at `app.example.com/*`. Calling `fetch()` will invoke the application Worker on your Custom Domain. Note that Routes cannot be the target of a same-zone `fetch()` call.
18
17
19
18
## Set up a route
20
19
@@ -26,14 +25,14 @@ To add a route, you must have:
26
25
27
26
:::caution
28
27
29
-
Route setup will differ depending on if your application's origin is a Worker or not. If your Worker is your application's origin, use [Custom Domains](/workers/configuration/routing/custom-domains/).
28
+
Route setup will differ depending on if your application's origin is a Worker or not. If your Worker is your application's origin, use [Custom Domains](/workers/configuration/routing/custom-domains/).
30
29
:::
31
30
32
31
If your Worker is not your application's origin, follow the instructions below to set up a route.
33
32
34
33
:::note
35
34
36
-
Routes can also be created via the API. Refer to the [Workers Routes API documentation](/api/operations/worker-routes-list-routes) for more information.
35
+
Routes can also be created via the API. Refer to the [Workers Routes API documentation](/api/operations/worker-routes-create-route) for more information.
37
36
:::
38
37
39
38
### Set up a route in the dashboard
@@ -75,26 +74,7 @@ routes = [
75
74
76
75
:::note
77
76
78
-
The `zone_id` and `zone_name` options are interchangeable. However, if using Cloudflare for SaaS with a `*/*` pattern, use the `zone_name` option to avoid errors. Currently, [publishing `*/*` routes with a `zone_id` option fails with an `Invalid URL` error](https://github.com/cloudflare/workers-sdk/issues/2953).
79
-
:::
80
-
81
-
## Routes with `workers.dev`
82
-
83
-
When you create your Worker, a [`workers.dev`](/workers/configuration/routing/workers-dev/) route is automatically set up. Review your `workers.dev` route in your Worker > **Triggers** > **Routes**.
84
-
85
-
To disable the `workers.dev` route, include the following in your Worker's `wrangler.toml` file:
86
-
87
-
```toml
88
-
workers_dev = false
89
-
```
90
-
91
-
When you redeploy your Worker with this change, the `workers.dev` route will be disabled.
92
-
93
-
If you do not specify `workers_dev = false` but add a [`routes` component](/workers/wrangler/configuration/#routes) to your `wrangler.toml`, the value of `workers_dev` will be inferred as `false` on the next deploy.
94
-
95
-
:::caution
96
-
97
-
If you disable your `workers.dev` route in the Cloudflare dashboard but do not update your Worker's `wrangler.toml` file with `workers_dev = false`, the `workers.dev` route will re-enable the next time you publish your Worker.
77
+
The `zone_id` and `zone_name` options are interchangeable. However, if using Cloudflare for SaaS with a `*/*` pattern, use the `zone_name` option to avoid errors. Currently, [publishing `*/*` routes with a `zone_id` option fails with an `Invalid URL` error](https://github.com/cloudflare/workers-sdk/issues/2953).
98
78
:::
99
79
100
80
## Matching behavior
@@ -116,19 +96,19 @@ A pattern to match all requests looks like this:
116
96
117
97
While they look similar to a [regex](https://en.wikipedia.org/wiki/Regular_expression) pattern, route patterns follow specific rules:
118
98
119
-
* The only supported operator is the wildcard (`*`), which matches zero or more of any character.
99
+
- The only supported operator is the wildcard (`*`), which matches zero or more of any character.
120
100
121
-
* Route patterns may not contain infix wildcards or query parameters. For example, neither `example.com/*.jpg` nor `example.com/?foo=*` are valid route patterns.
101
+
- Route patterns may not contain infix wildcards or query parameters. For example, neither `example.com/*.jpg` nor `example.com/?foo=*` are valid route patterns.
122
102
123
-
* When more than one route pattern could match a request URL, the most specific route pattern wins. For example, the pattern `www.example.com/*` would take precedence over `*.example.com/*` when matching a request for `https://www.example.com/`. The pattern `example.com/hello/*` would take precedence over `example.com/*` when matching a request for `example.com/hello/world`.
103
+
- When more than one route pattern could match a request URL, the most specific route pattern wins. For example, the pattern `www.example.com/*` would take precedence over `*.example.com/*` when matching a request for `https://www.example.com/`. The pattern `example.com/hello/*` would take precedence over `example.com/*` when matching a request for `example.com/hello/world`.
124
104
125
-
* Route pattern matching considers the entire request URL, including the query parameter string. Since route patterns may not contain query parameters, the only way to have a route pattern match URLs with query parameters is to terminate it with a wildcard, `*`.
105
+
- Route pattern matching considers the entire request URL, including the query parameter string. Since route patterns may not contain query parameters, the only way to have a route pattern match URLs with query parameters is to terminate it with a wildcard, `*`.
126
106
127
-
* The path component of route patterns is case sensitive, for example, `example.com/Images/*` and `example.com/images/*` are two distinct routes.
107
+
- The path component of route patterns is case sensitive, for example, `example.com/Images/*` and `example.com/images/*` are two distinct routes.
128
108
129
-
* For routes created before October 15th, 2023, the host component of route patterns is case sensitive, for example, `example.com/*` and `Example.com/*` are two distinct routes.
109
+
- For routes created before October 15th, 2023, the host component of route patterns is case sensitive, for example, `example.com/*` and `Example.com/*` are two distinct routes.
130
110
131
-
* For routes created on or after October 15th, 2023, the host component of route patterns is not case sensitive, for example, `example.com/*` and `Example.com/*` are equivalent routes.
111
+
- For routes created on or after October 15th, 2023, the host component of route patterns is not case sensitive, for example, `example.com/*` and `Example.com/*` are equivalent routes.
132
112
133
113
A route can be specified without being associated with a Worker. This will act to negate any less specific patterns. For example, consider this pair of route patterns, one with a Workers script and one without:
134
114
@@ -137,7 +117,7 @@ A route can be specified without being associated with a Worker. This will act t
137
117
*example.com/images/* -> worker-script
138
118
```
139
119
140
-
In this example, all requests destined for example.com and whose paths are prefixed by `/images/` would be routed to `worker-script`, *except* for `/images/cat.png`, which would bypass Workers completely. Requests with a path of `/images/cat.png?foo=bar` would be routed to `worker-script`, due to the presence of the query string.
120
+
In this example, all requests destined for example.com and whose paths are prefixed by `/images/` would be routed to `worker-script`, _except_ for `/images/cat.png`, which would bypass Workers completely. Requests with a path of `/images/cat.png?foo=bar` would be routed to `worker-script`, due to the presence of the query string.
141
121
142
122
## Validity
143
123
@@ -155,30 +135,28 @@ For example, `https://example.com/?anything` is not a valid route pattern.
155
135
156
136
If you omit a scheme in your route pattern, it will match both `http://` and `https://` URLs. If you include `http://` or `https://`, it will only match HTTP or HTTPS requests, respectively.
157
137
158
-
*`https://*.example.com/` matches `https://www.example.com/` but not `http://www.example.com/`.
138
+
-`https://*.example.com/` matches `https://www.example.com/` but not `http://www.example.com/`.
159
139
160
-
*`*.example.com/` matches both `https://www.example.com/` and `http://www.example.com/`.
140
+
-`*.example.com/` matches both `https://www.example.com/` and `http://www.example.com/`.
161
141
162
142
#### Hostnames may optionally begin with `*`
163
143
164
144
If a route pattern hostname begins with `*`, then it matches the host and all subhosts. If a route pattern hostname begins with `*.`, then it only matches all subhosts.
165
145
166
-
*`*example.com/` matches `https://example.com/` and `https://www.example.com/`.
146
+
-`*example.com/` matches `https://example.com/` and `https://www.example.com/`.
167
147
168
-
*`*.example.com/` matches `https://www.example.com/` but not `https://example.com/`.
148
+
-`*.example.com/` matches `https://www.example.com/` but not `https://example.com/`.
169
149
170
150
#### Paths may optionally end with `*`
171
151
172
152
If a route pattern path ends with `*`, then it matches all suffixes of that path.
173
153
174
-
*`https://example.com/path*` matches `https://example.com/path` and `https://example.com/path2` and `https://example.com/path/readme.txt`
154
+
-`https://example.com/path*` matches `https://example.com/path` and `https://example.com/path2` and `https://example.com/path/readme.txt`
175
155
176
156
:::caution
177
157
178
-
179
158
There is a well-known bug associated with path matching concerning wildcards (`*`) and forward slashes (`/`) that is documented in [Known issues](/workers/platform/known-issues/).
180
159
181
-
182
160
:::
183
161
184
162
#### Domains and subdomains must have a DNS Record
@@ -187,8 +165,6 @@ All domains and subdomains must have a [DNS record](/dns/manage-dns-records/how-
187
165
188
166
:::caution
189
167
190
-
191
168
If you have previously used the Cloudflare dashboard to add an `AAAA` record for `myname` to `example.com`, pointing to `100::` (the [reserved IPv6 discard prefix](https://tools.ietf.org/html/rfc6666)), Cloudflare recommends creating a [Custom Domain](/workers/configuration/routing/custom-domains/) pointing to your Worker instead.
0 commit comments