Skip to content

Commit 6a5e1e1

Browse files
authored
Serving assets on a path docs (#18657)
1 parent 908b8b1 commit 6a5e1e1

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

src/content/docs/workers/static-assets/compatibility-matrix.mdx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ We plan to bridge the gaps between Workers and Pages and provide ways to migrate
4343
| [Middleware](/workers/static-assets/binding/#experimental_serve_directly) |[^2] ||
4444
| [Redirects](/pages/configuration/redirects/) | 🟡 [^3] ||
4545
| [Smart Placement](/workers/configuration/smart-placement/) |||
46+
| [Serve assets on a path](/workers/static-assets/routing/) |||
4647
| **Observability** | | |
4748
| [Workers Logs](/workers/observability/) |||
4849
| [Logpush](/workers/observability/logs/logpush/) |||

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

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,3 +282,43 @@ Take the following directory structure:
282282
/not-found -> 200 /index.html
283283
/folder/doesnt/exist -> 200 /index.html
284284
```
285+
286+
## Serving assets from a custom path
287+
288+
:::note
289+
This feature requires Wrangler v3.98.0 or later.
290+
:::
291+
292+
Like with any other Worker, [you can configure a Worker with assets to run on a path of your domain](/workers/configuration/routing/routes/).
293+
Assets defined for a Worker must be nested in a directory structure that mirrors the desired path.
294+
295+
For example, to serve assets from `example.com/blog/*`, create a `blog` directory in your asset directory.
296+
297+
{/* prettier-ignore */}
298+
<FileTree>
299+
- dist
300+
- blog
301+
- index.html
302+
- posts
303+
- post1.html
304+
- post2.html
305+
</FileTree>
306+
307+
With a Wrangler configuration file like so:
308+
309+
<WranglerConfig>
310+
```toml
311+
name = "assets-on-a-path-example"
312+
main = "src/index.js"
313+
route = "example.com/blog/*"
314+
315+
[assets]
316+
directory = "dist"
317+
318+
```
319+
</WranglerConfig>
320+
321+
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.
322+
323+
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`.
324+
However, if needed, these files can still be manually fetched over [the binding](/workers/static-assets/binding/#binding).

0 commit comments

Comments
 (0)