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 <gbrimble@cloudflare.com>
This commit is contained in:
lrapoport-cf 2025-05-08 15:08:59 -04:00 committed by GitHub
parent 62b3d02335
commit cd84b00d1e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 137 additions and 150 deletions

View file

@ -1,7 +1,6 @@
---
pcx_content_type: concept
title: Multipart upload metadata
---
import { Type, MetaInfo } from "~/components";
@ -12,15 +11,15 @@ If you're using the [Workers Script Upload API](/api/resources/workers/subresour
```json
{
"main_module": "main.js",
"bindings": [
{
"type": "plain_text",
"name": "MESSAGE",
"text": "Hello, world!"
}
],
"compatibility_date": "2021-09-14"
"main_module": "main.js",
"bindings": [
{
"type": "plain_text",
"name": "MESSAGE",
"text": "Hello, world!"
}
],
"compatibility_date": "2021-09-14"
}
```
@ -33,41 +32,38 @@ The following attributes are configurable at the top-level.
At a minimum, the `main_module` key is required to upload a Worker.
:::
- `main_module` <Type text="string" /> <MetaInfo text="required" />
- The part name that contains the module entry point of the Worker that will be executed. For example, `main.js`.
* `main_module` <Type text="string" /> <MetaInfo text="required" />
- `assets` <Type text="object" /> <MetaInfo text="optional" />
* The part name that contains the module entry point of the Worker that will be executed. For example, `main.js`.
- [Asset](/workers/static-assets/) configuration for a Worker.
- `config` <Type text="object" /> <MetaInfo text="optional" />
- [html_handling](/workers/static-assets/routing/advanced/html-handling/) determines the redirects and rewrites of requests for HTML content.
- [not_found_handling](/workers/static-assets/#routing-behavior) determines the response when a request does not match a static asset.
- `jwt` field provides a token authorizing assets to be attached to a Worker.
* `assets` <Type text="object" /> <MetaInfo text="optional" />
- `keep_assets` <Type text="boolean" /> <MetaInfo text="optional" />
* [Asset](/workers/static-assets/) configuration for a Worker.
* `config` <Type text="object" /> <MetaInfo text="optional" />
* [html_handling](/workers/static-assets/routing/advanced/html-handling/) determines the redirects and rewrites of requests for HTML content.
* [not_found_handling](/workers/static-assets/routing/) determines the response when a request does not match a static asset.
* `jwt` field provides a token authorizing assets to be attached to a Worker.
- Specifies whether assets should be retained from a previously uploaded Worker version; used in lieu of providing a completion token.
* `keep_assets` <Type text="boolean" /> <MetaInfo text="optional" />
- `bindings` array\[object] optional
* Specifies whether assets should be retained from a previously uploaded Worker version; used in lieu of providing a completion token.
- [Bindings](#bindings) to expose in the Worker.
* `bindings` array\[object] optional
- `placement` <Type text="object" /> <MetaInfo text="optional" />
* [Bindings](#bindings) to expose in the Worker.
- [Smart placement](/workers/configuration/smart-placement/) object for the Worker.
- `mode` field only supports `smart` for automatic placement.
* `placement` <Type text="object" /> <MetaInfo text="optional" />
- `compatibility_date` <Type text="string" /> <MetaInfo text="optional" />
* [Smart placement](/workers/configuration/smart-placement/) object for the Worker.
* `mode` field only supports `smart` for automatic placement.
- [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).
* `compatibility_date` <Type text="string" /> <MetaInfo text="optional" />
* [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).
* `compatibility_flags` array\[string] optional
* [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`.
- `compatibility_flags` array\[string] optional
- [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`.
## Additional attributes: [Workers Script Upload API](/api/resources/workers/subresources/scripts/methods/update/)
@ -78,25 +74,21 @@ For [immediately deployed uploads](/workers/configuration/versions-and-deploymen
These attributes are **not available** for version uploads.
:::
- `migrations` array\[object] optional
- [Durable Objects migrations](/durable-objects/reference/durable-objects-migrations/) to apply.
* `migrations` array\[object] optional
- `logpush` <Type text="boolean" /> <MetaInfo text="optional" />
* [Durable Objects migrations](/durable-objects/reference/durable-objects-migrations/) to apply.
- Whether [Logpush](/cloudflare-for-platforms/cloudflare-for-saas/hostname-analytics/#logpush) is turned on for the Worker.
* `logpush` <Type text="boolean" /> <MetaInfo text="optional" />
- `tail_consumers` array\[object] optional
* Whether [Logpush](/cloudflare-for-platforms/cloudflare-for-saas/hostname-analytics/#logpush) is turned on for the Worker.
* `tail_consumers` array\[object] optional
* [Tail Workers](/workers/observability/logs/tail-workers/) that will consume logs from the attached Worker.
* `tags` array\[string] optional
* List of strings to use as tags for this Worker.
- [Tail Workers](/workers/observability/logs/tail-workers/) that will consume logs from the attached Worker.
- `tags` array\[string] optional
- List of strings to use as tags for this Worker.
## Additional attributes: [Version Upload API](/api/resources/workers/subresources/scripts/subresources/versions/methods/create/)
@ -107,15 +99,11 @@ For [version uploads](/workers/configuration/versions-and-deployments/#upload-a-
These attributes are **not available** for immediately deployed uploads.
:::
- `annotations` <Type text="object" /> <MetaInfo text="optional" />
* `annotations` <Type text="object" /> <MetaInfo text="optional" />
* Annotations object specific to the Worker version.
* `workers/message` specifies a custom message for the version.
* `workers/tag` specifies a custom identifier for the version.
- Annotations object specific to the Worker version.
- `workers/message` specifies a custom message for the version.
- `workers/tag` specifies a custom identifier for the version.
## Bindings
@ -123,88 +111,88 @@ Workers can interact with resources on the Cloudflare Developer Platform using [
```json
{
"bindings": [
{
"type": "ai",
"name": "<VARIABLE_NAME>"
},
{
"type": "analytics_engine",
"name": "<VARIABLE_NAME>",
"dataset": "<DATASET>"
},
{
"type": "assets",
"name": "<VARIABLE_NAME>"
},
{
"type": "browser_rendering",
"name": "<VARIABLE_NAME>"
},
{
"type": "d1",
"name": "<VARIABLE_NAME>",
"id": "<D1_ID>"
},
{
"type": "durable_object_namespace",
"name": "<VARIABLE_NAME>",
"class_name": "<DO_CLASS_NAME>"
},
{
"type": "hyperdrive",
"name": "<VARIABLE_NAME>",
"id": "<HYPERDRIVE_ID>"
},
{
"type": "kv_namespace",
"name": "<VARIABLE_NAME>",
"namespace_id": "<KV_ID>"
},
{
"type": "mtls_certificate",
"name": "<VARIABLE_NAME>",
"certificate_id": "<MTLS_CERTIFICATE_ID>"
},
{
"type": "plain_text",
"name": "<VARIABLE_NAME>",
"text": "<VARIABLE_VALUE>"
},
{
"type": "queue",
"name": "<VARIABLE_NAME>",
"queue_name": "<QUEUE_NAME>"
},
{
"type": "r2_bucket",
"name": "<VARIABLE_NAME>",
"bucket_name": "<R2_BUCKET_NAME>"
},
{
"type": "secret_text",
"name": "<VARIABLE_NAME>",
"text": "<SECRET_VALUE>"
},
{
"type": "service",
"name": "<VARIABLE_NAME>",
"service": "<SERVICE_NAME>",
"environment": "production"
},
{
"type": "tail_consumer",
"service": "<WORKER_NAME>"
},
{
"type": "vectorize",
"name": "<VARIABLE_NAME>",
"index_name": "<INDEX_NAME>"
},
{
"type": "version_metadata",
"name": "<VARIABLE_NAME>"
}
]
"bindings": [
{
"type": "ai",
"name": "<VARIABLE_NAME>"
},
{
"type": "analytics_engine",
"name": "<VARIABLE_NAME>",
"dataset": "<DATASET>"
},
{
"type": "assets",
"name": "<VARIABLE_NAME>"
},
{
"type": "browser_rendering",
"name": "<VARIABLE_NAME>"
},
{
"type": "d1",
"name": "<VARIABLE_NAME>",
"id": "<D1_ID>"
},
{
"type": "durable_object_namespace",
"name": "<VARIABLE_NAME>",
"class_name": "<DO_CLASS_NAME>"
},
{
"type": "hyperdrive",
"name": "<VARIABLE_NAME>",
"id": "<HYPERDRIVE_ID>"
},
{
"type": "kv_namespace",
"name": "<VARIABLE_NAME>",
"namespace_id": "<KV_ID>"
},
{
"type": "mtls_certificate",
"name": "<VARIABLE_NAME>",
"certificate_id": "<MTLS_CERTIFICATE_ID>"
},
{
"type": "plain_text",
"name": "<VARIABLE_NAME>",
"text": "<VARIABLE_VALUE>"
},
{
"type": "queue",
"name": "<VARIABLE_NAME>",
"queue_name": "<QUEUE_NAME>"
},
{
"type": "r2_bucket",
"name": "<VARIABLE_NAME>",
"bucket_name": "<R2_BUCKET_NAME>"
},
{
"type": "secret_text",
"name": "<VARIABLE_NAME>",
"text": "<SECRET_VALUE>"
},
{
"type": "service",
"name": "<VARIABLE_NAME>",
"service": "<SERVICE_NAME>",
"environment": "production"
},
{
"type": "tail_consumer",
"service": "<WORKER_NAME>"
},
{
"type": "vectorize",
"name": "<VARIABLE_NAME>",
"index_name": "<INDEX_NAME>"
},
{
"type": "version_metadata",
"name": "<VARIABLE_NAME>"
}
]
}
```

View file

@ -25,7 +25,7 @@ import {
/>
---
**Or just deploy** - create a full-stack app using React, Hono API And Vite, with CI/CD and previews all set up for you.
**Or just deploy** - create a full-stack app using React, Hono API and Vite, with CI/CD and previews all set up for you.
[![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)

View file

@ -115,7 +115,7 @@ In the example above, assets would be available through `env.ASSETS`.
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')`.
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.
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.
<Tabs>
<TabItem label="JavaScript" icon="seti:javascript">
@ -178,4 +178,4 @@ Enabling Smart Placement with `run_worker_first=false` (or not specifying it) le
Use Smart Placement with `run_worker_first=false` (or not specifying it) when prioritizing fast asset delivery.
This will not impact the [default routing behavior](/workers/static-assets/routing/).
This will not impact the [default routing behavior](/workers/static-assets/#routing-behavior).

View file

@ -83,13 +83,12 @@ export default {
### Routing behavior
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.
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.
- 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.
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:
- 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.
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"`:
- [`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.
- [`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.
<WranglerConfig>

View file

@ -23,7 +23,7 @@ Take the following directory structure:
## Automatic trailing slashes (default)
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.
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.
<WranglerConfig>

View file

@ -8,7 +8,7 @@ sidebar:
import { WranglerConfig, Render } from "~/components";
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.
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.
Often, an SSG framework will allow you to create a custom 404 page.
@ -32,7 +32,7 @@ In order to deploy a Static Site Generation application to Workers, you must con
</WranglerConfig>
`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.
`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.
### Custom 404 pages

View file

@ -694,8 +694,8 @@ To bind Images to your Worker, assign an array of the below object to the `image
```jsonc
{
"images": {
"binding": "IMAGES", // i.e. available in your Worker on env.IMAGES
},
"binding": "IMAGES" // i.e. available in your Worker on env.IMAGES
}
}
```
@ -1037,7 +1037,7 @@ The following options are available under the `assets` key.
- `not_found_handling`: <Type text={'"single-page-application" | "404-page" | "none"'} /> <MetaInfo text={'optional, defaults to "none"'} />
- Determines the handling of requests that do not map to an asset. Learn more about the various options in [assets routing](/workers/static-assets/routing/).
- Determines the handling of requests that do not map to an asset. Learn more about the various options for [routing behavior](/workers/static-assets/#routing-behavior).
Example:

View file

@ -2,6 +2,6 @@
{}
---
By default, Cloudflare first tries to match a request path against a static asset path, which is based on the file structure of the uploaded asset directory. This is either the directory specified by `assets.directory` in your Wrangler config or, in the case of the [Cloudflare Vite plugin](/workers/vite-plugin/), the output directory of the client build. Failing that, we invoke a Worker if one is present. If there is no Worker, or the Worker then uses the asset binding, Cloudflare will fallback to the behaviour set by [`not_found_handling`](/workers/static-assets/routing/).
By default, Cloudflare first tries to match a request path against a static asset path, which is based on the file structure of the uploaded asset directory. This is either the directory specified by `assets.directory` in your Wrangler config or, in the case of the [Cloudflare Vite plugin](/workers/vite-plugin/), the output directory of the client build. Failing that, we invoke a Worker if one is present. If there is no Worker, or the Worker then uses the asset binding, Cloudflare will fallback to the behaviour set by [`not_found_handling`](/workers/static-assets/#routing-behavior).
Refer to the [routing documentation](/workers/static-assets/routing/) for more information about how routing works with static assets, and how to customize this behavior.