Skip to content

Commit dcd9c94

Browse files
lrapoport-cfGregBrimble
authored andcommitted
Assets updates (and typo fixes) (#22287)
* Fix typos * Update links for routing behavior and not_found_handling. * Update routing behavior section --------- Co-authored-by: Greg Brimble <[email protected]>
1 parent 3a8fb04 commit dcd9c94

File tree

8 files changed

+137
-150
lines changed

8 files changed

+137
-150
lines changed
Lines changed: 123 additions & 135 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
---
22
pcx_content_type: concept
33
title: Multipart upload metadata
4-
54
---
65

76
import { Type, MetaInfo } from "~/components";
@@ -12,15 +11,15 @@ If you're using the [Workers Script Upload API](/api/resources/workers/subresour
1211

1312
```json
1413
{
15-
"main_module": "main.js",
16-
"bindings": [
17-
{
18-
"type": "plain_text",
19-
"name": "MESSAGE",
20-
"text": "Hello, world!"
21-
}
22-
],
23-
"compatibility_date": "2021-09-14"
14+
"main_module": "main.js",
15+
"bindings": [
16+
{
17+
"type": "plain_text",
18+
"name": "MESSAGE",
19+
"text": "Hello, world!"
20+
}
21+
],
22+
"compatibility_date": "2021-09-14"
2423
}
2524
```
2625

@@ -33,41 +32,38 @@ The following attributes are configurable at the top-level.
3332
At a minimum, the `main_module` key is required to upload a Worker.
3433
:::
3534

35+
- `main_module` <Type text="string" /> <MetaInfo text="required" />
3636

37+
- The part name that contains the module entry point of the Worker that will be executed. For example, `main.js`.
3738

38-
* `main_module` <Type text="string" /> <MetaInfo text="required" />
39-
40-
* The part name that contains the module entry point of the Worker that will be executed. For example, `main.js`.
41-
42-
* `assets` <Type text="object" /> <MetaInfo text="optional" />
39+
- `assets` <Type text="object" /> <MetaInfo text="optional" />
4340

44-
* [Asset](/workers/static-assets/) configuration for a Worker.
45-
* `config` <Type text="object" /> <MetaInfo text="optional" />
46-
* [html_handling](/workers/static-assets/routing/advanced/html-handling/) determines the redirects and rewrites of requests for HTML content.
47-
* [not_found_handling](/workers/static-assets/routing/) determines the response when a request does not match a static asset.
48-
* `jwt` field provides a token authorizing assets to be attached to a Worker.
41+
- [Asset](/workers/static-assets/) configuration for a Worker.
42+
- `config` <Type text="object" /> <MetaInfo text="optional" />
43+
- [html_handling](/workers/static-assets/routing/advanced/html-handling/) determines the redirects and rewrites of requests for HTML content.
44+
- [not_found_handling](/workers/static-assets/#routing-behavior) determines the response when a request does not match a static asset.
45+
- `jwt` field provides a token authorizing assets to be attached to a Worker.
4946

50-
* `keep_assets` <Type text="boolean" /> <MetaInfo text="optional" />
47+
- `keep_assets` <Type text="boolean" /> <MetaInfo text="optional" />
5148

52-
* Specifies whether assets should be retained from a previously uploaded Worker version; used in lieu of providing a completion token.
49+
- Specifies whether assets should be retained from a previously uploaded Worker version; used in lieu of providing a completion token.
5350

54-
* `bindings` array\[object] optional
51+
- `bindings` array\[object] optional
5552

56-
* [Bindings](#bindings) to expose in the Worker.
53+
- [Bindings](#bindings) to expose in the Worker.
5754

58-
* `placement` <Type text="object" /> <MetaInfo text="optional" />
55+
- `placement` <Type text="object" /> <MetaInfo text="optional" />
5956

60-
* [Smart placement](/workers/configuration/smart-placement/) object for the Worker.
61-
* `mode` field only supports `smart` for automatic placement.
57+
- [Smart placement](/workers/configuration/smart-placement/) object for the Worker.
58+
- `mode` field only supports `smart` for automatic placement.
6259

63-
* `compatibility_date` <Type text="string" /> <MetaInfo text="optional" />
60+
- `compatibility_date` <Type text="string" /> <MetaInfo text="optional" />
6461

65-
* [Compatibility Date](/workers/configuration/compatibility-dates/#setting-compatibility-date) indicating targeted support in the Workers runtime. Backwards incompatible fixes to the runtime following this date will not affect this Worker. Highly recommended to set a `compatibility_date`, otherwise if on upload via the API, it defaults to the oldest compatibility date before any flags took effect (2021-11-02).
62+
- [Compatibility Date](/workers/configuration/compatibility-dates/#setting-compatibility-date) indicating targeted support in the Workers runtime. Backwards incompatible fixes to the runtime following this date will not affect this Worker. Highly recommended to set a `compatibility_date`, otherwise if on upload via the API, it defaults to the oldest compatibility date before any flags took effect (2021-11-02).
6663

67-
* `compatibility_flags` array\[string] optional
68-
69-
* [Compatibility Flags](/workers/configuration/compatibility-flags/#setting-compatibility-flags) that enable or disable certain features in the Workers runtime. Used to enable upcoming features or opt in or out of specific changes not included in a `compatibility_date`.
64+
- `compatibility_flags` array\[string] optional
7065

66+
- [Compatibility Flags](/workers/configuration/compatibility-flags/#setting-compatibility-flags) that enable or disable certain features in the Workers runtime. Used to enable upcoming features or opt in or out of specific changes not included in a `compatibility_date`.
7167

7268
## Additional attributes: [Workers Script Upload API](/api/resources/workers/subresources/scripts/methods/update/)
7369

@@ -78,25 +74,21 @@ For [immediately deployed uploads](/workers/configuration/versions-and-deploymen
7874
These attributes are **not available** for version uploads.
7975
:::
8076

77+
- `migrations` array\[object] optional
8178

79+
- [Durable Objects migrations](/durable-objects/reference/durable-objects-migrations/) to apply.
8280

83-
* `migrations` array\[object] optional
84-
85-
* [Durable Objects migrations](/durable-objects/reference/durable-objects-migrations/) to apply.
86-
87-
* `logpush` <Type text="boolean" /> <MetaInfo text="optional" />
81+
- `logpush` <Type text="boolean" /> <MetaInfo text="optional" />
8882

89-
* Whether [Logpush](/cloudflare-for-platforms/cloudflare-for-saas/hostname-analytics/#logpush) is turned on for the Worker.
83+
- Whether [Logpush](/cloudflare-for-platforms/cloudflare-for-saas/hostname-analytics/#logpush) is turned on for the Worker.
9084

91-
* `tail_consumers` array\[object] optional
85+
- `tail_consumers` array\[object] optional
9286

93-
* [Tail Workers](/workers/observability/logs/tail-workers/) that will consume logs from the attached Worker.
94-
95-
* `tags` array\[string] optional
96-
97-
* List of strings to use as tags for this Worker.
87+
- [Tail Workers](/workers/observability/logs/tail-workers/) that will consume logs from the attached Worker.
9888

89+
- `tags` array\[string] optional
9990

91+
- List of strings to use as tags for this Worker.
10092

10193
## Additional attributes: [Version Upload API](/api/resources/workers/subresources/scripts/subresources/versions/methods/create/)
10294

@@ -107,104 +99,100 @@ For [version uploads](/workers/configuration/versions-and-deployments/#upload-a-
10799
These attributes are **not available** for immediately deployed uploads.
108100
:::
109101

102+
- `annotations` <Type text="object" /> <MetaInfo text="optional" />
110103

111-
112-
* `annotations` <Type text="object" /> <MetaInfo text="optional" />
113-
114-
* Annotations object specific to the Worker version.
115-
* `workers/message` specifies a custom message for the version.
116-
* `workers/tag` specifies a custom identifier for the version.
117-
118-
104+
- Annotations object specific to the Worker version.
105+
- `workers/message` specifies a custom message for the version.
106+
- `workers/tag` specifies a custom identifier for the version.
119107

120108
## Bindings
121109

122110
Workers can interact with resources on the Cloudflare Developer Platform using [bindings](/workers/runtime-apis/bindings/). Refer to the JSON example below that shows how to add bindings in the `metadata` part.
123111

124112
```json
125113
{
126-
"bindings": [
127-
{
128-
"type": "ai",
129-
"name": "<VARIABLE_NAME>"
130-
},
131-
{
132-
"type": "analytics_engine",
133-
"name": "<VARIABLE_NAME>",
134-
"dataset": "<DATASET>"
135-
},
136-
{
137-
"type": "assets",
138-
"name": "<VARIABLE_NAME>"
139-
},
140-
{
141-
"type": "browser_rendering",
142-
"name": "<VARIABLE_NAME>"
143-
},
144-
{
145-
"type": "d1",
146-
"name": "<VARIABLE_NAME>",
147-
"id": "<D1_ID>"
148-
},
149-
{
150-
"type": "durable_object_namespace",
151-
"name": "<VARIABLE_NAME>",
152-
"class_name": "<DO_CLASS_NAME>"
153-
},
154-
{
155-
"type": "hyperdrive",
156-
"name": "<VARIABLE_NAME>",
157-
"id": "<HYPERDRIVE_ID>"
158-
},
159-
{
160-
"type": "kv_namespace",
161-
"name": "<VARIABLE_NAME>",
162-
"namespace_id": "<KV_ID>"
163-
},
164-
{
165-
"type": "mtls_certificate",
166-
"name": "<VARIABLE_NAME>",
167-
"certificate_id": "<MTLS_CERTIFICATE_ID>"
168-
},
169-
{
170-
"type": "plain_text",
171-
"name": "<VARIABLE_NAME>",
172-
"text": "<VARIABLE_VALUE>"
173-
},
174-
{
175-
"type": "queue",
176-
"name": "<VARIABLE_NAME>",
177-
"queue_name": "<QUEUE_NAME>"
178-
},
179-
{
180-
"type": "r2_bucket",
181-
"name": "<VARIABLE_NAME>",
182-
"bucket_name": "<R2_BUCKET_NAME>"
183-
},
184-
{
185-
"type": "secret_text",
186-
"name": "<VARIABLE_NAME>",
187-
"text": "<SECRET_VALUE>"
188-
},
189-
{
190-
"type": "service",
191-
"name": "<VARIABLE_NAME>",
192-
"service": "<SERVICE_NAME>",
193-
"environment": "production"
194-
},
195-
{
196-
"type": "tail_consumer",
197-
"service": "<WORKER_NAME>"
198-
},
199-
{
200-
"type": "vectorize",
201-
"name": "<VARIABLE_NAME>",
202-
"index_name": "<INDEX_NAME>"
203-
},
204-
{
205-
"type": "version_metadata",
206-
"name": "<VARIABLE_NAME>"
207-
}
208-
]
114+
"bindings": [
115+
{
116+
"type": "ai",
117+
"name": "<VARIABLE_NAME>"
118+
},
119+
{
120+
"type": "analytics_engine",
121+
"name": "<VARIABLE_NAME>",
122+
"dataset": "<DATASET>"
123+
},
124+
{
125+
"type": "assets",
126+
"name": "<VARIABLE_NAME>"
127+
},
128+
{
129+
"type": "browser_rendering",
130+
"name": "<VARIABLE_NAME>"
131+
},
132+
{
133+
"type": "d1",
134+
"name": "<VARIABLE_NAME>",
135+
"id": "<D1_ID>"
136+
},
137+
{
138+
"type": "durable_object_namespace",
139+
"name": "<VARIABLE_NAME>",
140+
"class_name": "<DO_CLASS_NAME>"
141+
},
142+
{
143+
"type": "hyperdrive",
144+
"name": "<VARIABLE_NAME>",
145+
"id": "<HYPERDRIVE_ID>"
146+
},
147+
{
148+
"type": "kv_namespace",
149+
"name": "<VARIABLE_NAME>",
150+
"namespace_id": "<KV_ID>"
151+
},
152+
{
153+
"type": "mtls_certificate",
154+
"name": "<VARIABLE_NAME>",
155+
"certificate_id": "<MTLS_CERTIFICATE_ID>"
156+
},
157+
{
158+
"type": "plain_text",
159+
"name": "<VARIABLE_NAME>",
160+
"text": "<VARIABLE_VALUE>"
161+
},
162+
{
163+
"type": "queue",
164+
"name": "<VARIABLE_NAME>",
165+
"queue_name": "<QUEUE_NAME>"
166+
},
167+
{
168+
"type": "r2_bucket",
169+
"name": "<VARIABLE_NAME>",
170+
"bucket_name": "<R2_BUCKET_NAME>"
171+
},
172+
{
173+
"type": "secret_text",
174+
"name": "<VARIABLE_NAME>",
175+
"text": "<SECRET_VALUE>"
176+
},
177+
{
178+
"type": "service",
179+
"name": "<VARIABLE_NAME>",
180+
"service": "<SERVICE_NAME>",
181+
"environment": "production"
182+
},
183+
{
184+
"type": "tail_consumer",
185+
"service": "<WORKER_NAME>"
186+
},
187+
{
188+
"type": "vectorize",
189+
"name": "<VARIABLE_NAME>",
190+
"index_name": "<INDEX_NAME>"
191+
},
192+
{
193+
"type": "version_metadata",
194+
"name": "<VARIABLE_NAME>"
195+
}
196+
]
209197
}
210198
```

src/content/docs/workers/frameworks/framework-guides/react.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import {
2525
/>
2626
---
2727

28-
**Or just deploy** - create a full-stack app using React, Hono API And Vite, with CI/CD and previews all set up for you.
28+
**Or just deploy** - create a full-stack app using React, Hono API and Vite, with CI/CD and previews all set up for you.
2929

3030
[![Deploy to Workers](https://deploy.workers.cloudflare.com/button)](https://dash.cloudflare.com/?to=/:account/workers-and-pages/create/deploy-to-workers&repository=https://github.com/cloudflare/templates/tree/staging/vite-react-template)
3131

src/content/docs/workers/static-assets/binding.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ In the example above, assets would be available through `env.ASSETS`.
115115

116116
Your dynamic code can make new, or forward incoming requests to your project's static assets using the assets binding. For example, `env.ASSETS.fetch(request)`, `env.ASSETS.fetch(new URL('https://assets.local/my-file'))` or `env.ASSETS.fetch('https://assets.local/my-file')`.
117117

118-
Take the following example that configures a Worker script to return a response under all requests headed for `/api/`. Otherwise, the Worker script will pass the incoming request through to the asset binding. In this case, because a Worker script is only invoked when the requested route has not matched any static assets, this will always evaluate [`not_found_handling`](/workers/static-assets/routing/) behavior.
118+
Take the following example that configures a Worker script to return a response under all requests headed for `/api/`. Otherwise, the Worker script will pass the incoming request through to the asset binding. In this case, because a Worker script is only invoked when the requested route has not matched any static assets, this will always evaluate [`not_found_handling`](/workers/static-assets/#routing-behavior) behavior.
119119

120120
<Tabs>
121121
<TabItem label="JavaScript" icon="seti:javascript">
@@ -178,4 +178,4 @@ Enabling Smart Placement with `run_worker_first=false` (or not specifying it) le
178178

179179
Use Smart Placement with `run_worker_first=false` (or not specifying it) when prioritizing fast asset delivery.
180180

181-
This will not impact the [default routing behavior](/workers/static-assets/routing/).
181+
This will not impact the [default routing behavior](/workers/static-assets/#routing-behavior).

src/content/docs/workers/static-assets/index.mdx

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,13 +83,12 @@ export default {
8383

8484
### Routing behavior
8585

86-
By default, if a requested URL matches a file in the static assets directory, that file will always be served — without running Worker code. If no matching asset is found and a Worker is configured, the request will be processed by the Worker instead.
86+
By default, if a requested URL matches a file in the static assets directory, that file will be served — without invoking Worker code. If no matching asset is found and a Worker script is present, the request will be processed by the Worker. The Worker can return a response or choose to defer again to static assets by using the [assets binding](/workers/static-assets/binding/) (e.g. `env.ASSETS.fetch(request)`). If no Worker script is present, a `404 Not Found` response is returned.
8787

88-
- If no Worker is set up, the [`not_found_handling`](/workers/static-assets/routing/) setting in your Wrangler configuration determines what happens next. By default, a `404 Not Found` response is returned.
88+
The default behavior for requests which don't match a static asset can be changed by setting the [`not_found_handling` option under `assets`](/workers/wrangler/configuration/#assets) in your Wrangler configuration file:
8989

90-
- If a Worker is configured and a request does not match a static asset, the Worker will handle the request. The Worker can choose to pass the request to the asset binding (through `env.ASSETS.fetch()`), following the `not_found_handling` rules.
91-
92-
You can configure and override this default routing behaviour. For example, if you have a Single Page Application and want to serve `index.html` for all unmatched routes, you can set `not_found_handling = "single-page-application"`:
90+
- [`not_found_handling = "single-page-application"`](/workers/static-assets/routing/single-page-application/): Sets your application to return a `200 OK` response with `index.html` for requests which don't match a static asset. Use this if you have a Single Page Application.
91+
- [`not_found_handling = "404-page"`](/workers/static-assets/routing/static-site-generation/#custom-404-pages): Sets your application to return a `404 Not Found` response with the nearest `404.html` for requests which don't match a static asset.
9392

9493
<WranglerConfig>
9594

src/content/docs/workers/static-assets/routing/advanced/html-handling.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ Take the following directory structure:
2323

2424
## Automatic trailing slashes (default)
2525

26-
This will usually give you the desired behavior automatically: individual files (e.g. `foo.html`) will be served _without_ a trailing flash and folder index files (e.g. `foo/index.html`) will be served _with_ a trailing slash.
26+
This will usually give you the desired behavior automatically: individual files (e.g. `foo.html`) will be served _without_ a trailing slash and folder index files (e.g. `foo/index.html`) will be served _with_ a trailing slash.
2727

2828
<WranglerConfig>
2929

src/content/docs/workers/static-assets/routing/static-site-generation.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ sidebar:
88

99
import { WranglerConfig, Render } from "~/components";
1010

11-
Static Site Generation (SSG) applications are web applications which are predominantely built or "prerendered" ahead-of-time. They are often built with a framework such as [Gatsby](/workers/frameworks/framework-guides/gatsby/) or [Docusaurus](/workers/frameworks/framework-guides/docusaurus/). The build process of these frameworks will produce a many HTML files and accompanying client-side resources (e.g. JavaScript bundles, CSS stylesheets, images, fonts, etc.). Data is either static, fetched and compiled into the HTML at build-time, or fetched by the client from an API with client-side requests.
11+
Static Site Generation (SSG) applications are web applications which are predominantely built or "prerendered" ahead-of-time. They are often built with a framework such as [Gatsby](/workers/frameworks/framework-guides/gatsby/) or [Docusaurus](/workers/frameworks/framework-guides/docusaurus/). The build process of these frameworks will produce many HTML files and accompanying client-side resources (e.g. JavaScript bundles, CSS stylesheets, images, fonts, etc.). Data is either static, fetched and compiled into the HTML at build-time, or fetched by the client from an API with client-side requests.
1212

1313
Often, an SSG framework will allow you to create a custom 404 page.
1414

@@ -32,7 +32,7 @@ In order to deploy a Static Site Generation application to Workers, you must con
3232

3333
</WranglerConfig>
3434

35-
`assets.html_handling` defaults to `auto-trailing-slash` and this will usually give you the desired behavior automatically: individual files (e.g. `foo.html`) will be served _without_ a trailing flash and folder index files (e.g. `foo/index.html`) will be served _with_ a trailing slash. Alternatively, you can force trailing slashes (`force-trailing-slash`) or drop trailing slashes (`drop-trailing-slash`) on requests for HTML pages.
35+
`assets.html_handling` defaults to `auto-trailing-slash` and this will usually give you the desired behavior automatically: individual files (e.g. `foo.html`) will be served _without_ a trailing slash and folder index files (e.g. `foo/index.html`) will be served _with_ a trailing slash. Alternatively, you can force trailing slashes (`force-trailing-slash`) or drop trailing slashes (`drop-trailing-slash`) on requests for HTML pages.
3636

3737
### Custom 404 pages
3838

0 commit comments

Comments
 (0)