From 85e257a62ded99eb14903e448fa26754be9537a3 Mon Sep 17 00:00:00 2001 From: Daniel Walsh Date: Mon, 23 Dec 2024 15:14:52 +0000 Subject: [PATCH] Update Assets syntax to more standardised table --- .../docs/workers/static-assets/binding.mdx | 22 +++++++++++-------- .../docs/workers/static-assets/index.mdx | 6 ++--- 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/src/content/docs/workers/static-assets/binding.mdx b/src/content/docs/workers/static-assets/binding.mdx index e9670fe0d8b3d0..337af00b4f6ff8 100644 --- a/src/content/docs/workers/static-assets/binding.mdx +++ b/src/content/docs/workers/static-assets/binding.mdx @@ -72,7 +72,10 @@ compatibility_date = "2024-09-19" main = "src/index.ts" # The following configuration unconditionally invokes the Worker script at # `src/index.ts`, which can programatically fetch assets via the ASSETS binding -assets = { directory = "./public/", binding = "ASSETS", experimental_serve_directly = false } +[assets] +directory = "./public/" +binding = "ASSETS" +experimental_serve_directly = false ``` @@ -88,7 +91,9 @@ name = "my-worker" main = "./src/index.js" compatibility_date = "2024-09-19" -assets = { directory = "./public/", binding = "ASSETS" } +[assets] +directory = "./public/" +binding = "ASSETS" ``` @@ -113,8 +118,8 @@ Your dynamic code can make new, or forward incoming, requests to your project's 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/#routing-configuration) behavior. - - + + ```js export default { async fetch(request, env) { @@ -129,9 +134,8 @@ export default { }, }; ``` - - - + + ```ts interface Env { ASSETS: Fetcher; @@ -150,8 +154,8 @@ export default { }, } satisfies ExportedHandler; ``` - - + + ## Routing configuration diff --git a/src/content/docs/workers/static-assets/index.mdx b/src/content/docs/workers/static-assets/index.mdx index f60106221868a3..63f357d629a250 100644 --- a/src/content/docs/workers/static-assets/index.mdx +++ b/src/content/docs/workers/static-assets/index.mdx @@ -67,17 +67,17 @@ Requests to a project with static assets can either return static assets or invo **Requests to static assets are free and unlimited**. Requests to the Worker script (e.g. in the case of SSR content) are billed according to Workers pricing. Refer to [pricing](/workers/platform/pricing/#example-2) for an example. -There's no additional cost for storing Assets. +There's no additional cost for storing Assets. ### Troubleshooting -- `assets.bucket is a required field` — if you see this error, you need to update Wrangler to at least `3.78.10` or later. `bucket` is not a required field. +- `assets.bucket is a required field` — if you see this error, you need to update Wrangler to at least `3.78.10` or later. `bucket` is not a required field. ### Limitations The following limitations apply for Workers with static assets: -- There is a 20,000 file count limit per [Worker version](/workers/configuration/versions-and-deployments/), and a 25 MiB individual file size limit. This matches the [limits in Cloudflare Pages](/pages/platform/limits/) today. +- There is a 20,000 file count limit per [Worker version](/workers/configuration/versions-and-deployments/), and a 25 MiB individual file size limit. This matches the [limits in Cloudflare Pages](/pages/platform/limits/) today. - You cannot upload static assets to [Workers for Platforms](/cloudflare-for-platforms/workers-for-platforms/) [user workers](/cloudflare-for-platforms/workers-for-platforms/reference/how-workers-for-platforms-works/). This is a temporary limitation, we are working to remove it. - In local development, you cannot make [Service Binding RPC calls](/workers/runtime-apis/bindings/service-bindings/rpc/) to a Worker with static assets. This is a temporary limitation, we are working to remove it. - Workers with assets cannot run on a [route or domain](/workers/configuration/routing/) with a path component. For example, `example.com/*` is an acceptable route, but `example.com/foo/*` is not. Wrangler and the Cloudflare dashboard will throw an error when you try and add a route with a path component.