Skip to content

Commit 50612e7

Browse files
committed
Serving assets on a path docs
1 parent 2708df3 commit 50612e7

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](/pages/functions/middleware/) | 🟡 [^3] ||
4444
| [Redirects](/pages/configuration/redirects/) | 🟡 [^4] ||
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
@@ -218,3 +218,43 @@ Take the following directory structure:
218218
/not-found -> 200 /index.html
219219
/folder/doesnt/exist -> 200 /index.html
220220
```
221+
222+
## Serving assets from a custom path
223+
224+
:::note
225+
This feature requires Wrangler v3.xx.xx or later.
226+
:::
227+
228+
Like with any other Worker, [you can configure a Worker with assets to run on a path of your domain](/workers/configuration/routing/routes/).
229+
Assets defined for a Worker must be nested in a directory structure that mirrors the desired path.
230+
231+
For example, to serve assets from `example.com/blog/*`, create a `blog` directory in your asset directory.
232+
233+
{/* prettier-ignore */}
234+
<FileTree>
235+
- dist
236+
- blog
237+
- index.html
238+
- posts
239+
- post1.html
240+
- post2.html
241+
</FileTree>
242+
243+
With a Wrangler configuration file like so:
244+
245+
<WranglerConfig>
246+
```toml
247+
name = "assets-on-a-path-example"
248+
main = "src/index.js"
249+
route = "example.com/blog/*"
250+
251+
[assets]
252+
directory = "dist"
253+
254+
```
255+
</WranglerConfig>
256+
257+
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.
258+
259+
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).
260+
```

0 commit comments

Comments
 (0)