diff --git a/src/content/docs/workers/static-assets/compatibility-matrix.mdx b/src/content/docs/workers/static-assets/compatibility-matrix.mdx index 64dce6edb8e071c..d2da699d0a2b38f 100644 --- a/src/content/docs/workers/static-assets/compatibility-matrix.mdx +++ b/src/content/docs/workers/static-assets/compatibility-matrix.mdx @@ -43,6 +43,7 @@ We plan to bridge the gaps between Workers and Pages and provide ways to migrate | [Middleware](/workers/static-assets/binding/#experimental_serve_directly) | ✅ [^2] | ✅ | | [Redirects](/pages/configuration/redirects/) | 🟡 [^3] | ✅ | | [Smart Placement](/workers/configuration/smart-placement/) | ✅ | ✅ | +| [Serve assets on a path](/workers/static-assets/routing/) | ✅ | ❌ | | **Observability** | | | | [Workers Logs](/workers/observability/) | ✅ | ❌ | | [Logpush](/workers/observability/logs/logpush/) | ✅ | ❌ | diff --git a/src/content/docs/workers/static-assets/routing.mdx b/src/content/docs/workers/static-assets/routing.mdx index 88b62eec8ab81ff..14976650b978e99 100644 --- a/src/content/docs/workers/static-assets/routing.mdx +++ b/src/content/docs/workers/static-assets/routing.mdx @@ -282,3 +282,43 @@ Take the following directory structure: /not-found -> 200 /index.html /folder/doesnt/exist -> 200 /index.html ``` + +## Serving assets from a custom path + +:::note +This feature requires Wrangler v3.98.0 or later. +::: + +Like with any other Worker, [you can configure a Worker with assets to run on a path of your domain](/workers/configuration/routing/routes/). +Assets defined for a Worker must be nested in a directory structure that mirrors the desired path. + +For example, to serve assets from `example.com/blog/*`, create a `blog` directory in your asset directory. + +{/* prettier-ignore */} + +- dist + - blog + - index.html + - posts + - post1.html + - post2.html + + +With a Wrangler configuration file like so: + + +```toml +name = "assets-on-a-path-example" +main = "src/index.js" +route = "example.com/blog/*" + +[assets] +directory = "dist" + +``` + + +In this example, requests to `example.com/blog/` will serve the `index.html` file, and requests to `example.com/blog/posts/post1` will serve the `post1.html` file. + +If you have a file outside the configured path, it will not be served. For example, if you have a `home.html` file in the root of your asset directory, it will not be served when requesting `example.com/blog/home`. +However, if needed, these files can still be manually fetched over [the binding](/workers/static-assets/binding/#binding).