Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
258 changes: 123 additions & 135 deletions src/content/docs/workers/configuration/multipart-upload-metadata.mdx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
---
pcx_content_type: concept
title: Multipart upload metadata

---

import { Type, MetaInfo } from "~/components";
Expand All @@ -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"
}
```

Expand All @@ -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" />

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

* `assets` <Type text="object" /> <MetaInfo text="optional" />
- `assets` <Type text="object" /> <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.
- [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.

* `keep_assets` <Type text="boolean" /> <MetaInfo text="optional" />
- `keep_assets` <Type text="boolean" /> <MetaInfo text="optional" />

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

* `bindings` array\[object] optional
- `bindings` array\[object] optional

* [Bindings](#bindings) to expose in the Worker.
- [Bindings](#bindings) to expose in the Worker.

* `placement` <Type text="object" /> <MetaInfo text="optional" />
- `placement` <Type text="object" /> <MetaInfo text="optional" />

* [Smart placement](/workers/configuration/smart-placement/) object for the Worker.
* `mode` field only supports `smart` for automatic placement.
- [Smart placement](/workers/configuration/smart-placement/) object for the Worker.
- `mode` field only supports `smart` for automatic placement.

* `compatibility_date` <Type text="string" /> <MetaInfo text="optional" />
- `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 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/)

Expand All @@ -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

* [Durable Objects migrations](/durable-objects/reference/durable-objects-migrations/) to apply.

* `logpush` <Type text="boolean" /> <MetaInfo text="optional" />
- `logpush` <Type text="boolean" /> <MetaInfo text="optional" />

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

* `tail_consumers` array\[object] optional
- `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/)

Expand All @@ -107,104 +99,100 @@ 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

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.

```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>"
}
]
}
```
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
4 changes: 2 additions & 2 deletions src/content/docs/workers/static-assets/binding.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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">
Expand Down Expand Up @@ -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).
9 changes: 4 additions & 5 deletions src/content/docs/workers/static-assets/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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 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. The Worker can choose to pass the request to the asset binding (through `env.ASSETS.fetch()`). If no worker is set up, 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 when neither an asset nor a Worker is found can be changed by setting the [`not_found_handling` option under `assets`](/workers/wrangler/configuration/#assets) in your Wrangler configuration:

- 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"`: Sets your application to return `index.html` for unmatched routes. Use this if you have a Single Page Application.
- `not_found_handling = "404-page""`: Sets your application to return `404.html` for unmatched routes.

<WranglerConfig>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand All @@ -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

Expand Down
Loading